Skip to content

Commit 6229e7f

Browse files
committed
first draft; no tests
1 parent 6ecb11b commit 6229e7f

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

packages/catlog/src/stdlib/analyses/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
pub mod ode;
55

66
pub mod reachability;
7+
pub mod signed_links_to_signed_cat;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//! Migration for going from categories with signed links to signed categories
2+
// (e.g. from signed stock-flow diagrams to causal loop diagrams)
3+
4+
use crate::dbl::discrete_tabulator::theory::TabMorType;
5+
use crate::dbl::discrete_tabulator::theory::TabObType;
6+
use std::rc::Rc;
7+
8+
use crate::dbl::discrete::model::DiscreteDblModel;
9+
use crate::dbl::discrete_tabulator::model::DiscreteTabModel;
10+
use crate::dbl::model::{FgDblModel, MutDblModel};
11+
use crate::one::category::FgCategory;
12+
use crate::one::path::Path;
13+
use crate::stdlib::theories;
14+
use crate::zero::name;
15+
16+
/** Span-migration for categories with signed links.
17+
*
18+
* We create a CLD from a category with signed links from the query defined on
19+
* objects as
20+
*
21+
* V |-> stock : S | flow : F
22+
* E+ |-> out : F | link : L+
23+
* E- |-> in : F | link : L-
24+
*
25+
* and on morphisms as (...) something that will be written up eventually, but
26+
* in short can be described quite simply in words:
27+
*
28+
* - For each stock, create a vertex
29+
* - For each flow, create a (+,-)-span, where the apex is a new vertex
30+
* corresponding to the flow, and there is a negative arrow to the (vertex
31+
* corresponding to the) source of the flow, and a positive arrow to the
32+
* (vertex corresponding to the) target of the flow
33+
* - For each (signed) link, create an arrow (of the same sign) from the
34+
* (vertex corresponding to the) source stock to the (vertex corresponding
35+
* to the) target flow
36+
*/
37+
pub fn migrate(model: DiscreteTabModel) -> DiscreteDblModel {
38+
let mut migrated_model: DiscreteDblModel =
39+
DiscreteDblModel::new(Rc::new(theories::th_signed_category()));
40+
41+
let stock_type = TabObType::Basic(name("Object"));
42+
let flow_type = TabMorType::Hom(Box::new(stock_type.clone()));
43+
let pos_link_type = TabMorType::Basic(name("Link"));
44+
let neg_link_type = TabMorType::Basic(name("NegativeLink"));
45+
46+
// Create an object for each stock (a "stock-object")
47+
for s in model.ob_generators() {
48+
migrated_model.add_ob(s.clone(), name("Object"));
49+
}
50+
51+
// Create a span for each flow
52+
for f in model.mor_generators_with_type(&flow_type) {
53+
// An object for each flow (a "flow-object")
54+
migrated_model.add_ob(f.clone(), name("Object"));
55+
// A negative link from the flow object to the flow-source object
56+
migrated_model.add_mor(
57+
format!("{}_in", f).as_str().into(),
58+
f.clone(),
59+
model.mor_generator_dom(&f).unwrap_basic(),
60+
Path::Id(name("Object")),
61+
);
62+
// A positive link from the flow object to the flow-target object
63+
migrated_model.add_mor(
64+
format!("{}_in", f).as_str().into(),
65+
f.clone(),
66+
model.mor_generator_cod(&f).unwrap_basic(),
67+
name("Negative").into(),
68+
);
69+
}
70+
71+
// Create a positive arrow for each positive link
72+
for pl in model.mor_generators_with_type(&pos_link_type) {
73+
migrated_model.add_mor(
74+
pl.clone(),
75+
model.mor_generator_dom(&pl).unwrap_basic(),
76+
model.mor_generator_cod(&pl).unwrap_basic(),
77+
Path::Id(name("Object")),
78+
);
79+
}
80+
// Create a negative arrow for each negative link
81+
for nl in model.mor_generators_with_type(&neg_link_type) {
82+
migrated_model.add_mor(
83+
nl.clone(),
84+
model.mor_generator_dom(&nl).unwrap_basic(),
85+
model.mor_generator_cod(&nl).unwrap_basic(),
86+
name("Negative").into(),
87+
);
88+
}
89+
90+
migrated_model
91+
}

0 commit comments

Comments
 (0)