11//! Migration for going from categories with signed links to signed categories
22// (e.g. from signed stock-flow diagrams to causal loop diagrams)
3+ //
4+ // Note that this migration expects a DiscreteTabModel whose underlying theory
5+ // is th_category_signed_links, otherwise it will panic
36
4- use crate :: dbl:: discrete_tabulator:: theory:: TabMorType ;
5- use crate :: dbl:: discrete_tabulator:: theory:: TabObType ;
7+ use crate :: dbl:: discrete_tabulator:: theory:: { TabMorType , TabObType } ;
68use std:: rc:: Rc ;
79
810use crate :: dbl:: discrete:: model:: DiscreteDblModel ;
@@ -44,58 +46,73 @@ pub fn span_migrate(model: DiscreteTabModel) -> DiscreteDblModel {
4446 let neg_link_type = TabMorType :: Basic ( name ( "NegativeLink" ) ) ;
4547
4648 // 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+ for stock in model. ob_generators ( ) {
50+ migrated_model. add_ob ( stock . clone ( ) , name ( "Object" ) ) ;
4951 }
5052
5153 // Create a span for each flow
52- for f in model. mor_generators_with_type ( & flow_type) {
54+ for flow in model. mor_generators_with_type ( & flow_type) {
5355 // An object for each flow (a "flow-object")
54- migrated_model. add_ob ( f . clone ( ) , name ( "Object" ) ) ;
56+ migrated_model. add_ob ( flow . clone ( ) , name ( "Object" ) ) ;
5557 // A negative link from the flow object to the flow-source object
5658 migrated_model. add_mor (
57- format ! ( "{}_in" , f ) . as_str ( ) . into ( ) ,
58- f . clone ( ) ,
59- model. mor_generator_dom ( & f ) . unwrap_basic ( ) ,
59+ format ! ( "{}_in" , flow ) . as_str ( ) . into ( ) ,
60+ flow . clone ( ) ,
61+ model. mor_generator_dom ( & flow ) . unwrap_basic ( ) ,
6062 name ( "Negative" ) . into ( ) ,
6163 ) ;
6264 // A positive link from the flow object to the flow-target object
6365 migrated_model. add_mor (
64- format ! ( "{}_out" , f ) . as_str ( ) . into ( ) ,
65- f . clone ( ) ,
66- model. mor_generator_cod ( & f ) . unwrap_basic ( ) ,
66+ format ! ( "{}_out" , flow ) . as_str ( ) . into ( ) ,
67+ flow . clone ( ) ,
68+ model. mor_generator_cod ( & flow ) . unwrap_basic ( ) ,
6769 Path :: Id ( name ( "Object" ) ) ,
6870 ) ;
6971 }
7072
7173 // Create a positive arrow for each positive link
7274 for pl in model. mor_generators_with_type ( & pos_link_type) {
75+ // We know, by design, that the codomain of a morphism generator of type
76+ // pos_link_type will be of type TabOb::Tabulated and furthermore will
77+ // contain (in its box) a path (TabMor) consisting of a *single* TabEdge
78+ // which will *furthermore* itself be of type TabEdge::Basic
79+ let pl_cod = model
80+ . mor_generator_cod ( & pl)
81+ . unwrap_tabulated ( )
82+ . only ( )
83+ . expect ( "Morphism should be a singleton path of type TabEdge" )
84+ . unwrap_basic ( ) ;
7385 migrated_model. add_mor (
7486 pl. clone ( ) ,
7587 model. mor_generator_dom ( & pl) . unwrap_basic ( ) ,
76- model . mor_generator_cod ( & pl ) . unwrap_basic ( ) ,
88+ pl_cod ,
7789 Path :: Id ( name ( "Object" ) ) ,
7890 ) ;
7991 }
8092 // Create a negative arrow for each negative link
8193 for nl in model. mor_generators_with_type ( & neg_link_type) {
94+ let nl_cod = model
95+ . mor_generator_cod ( & nl)
96+ . unwrap_tabulated ( )
97+ . only ( )
98+ . expect ( "Morphism should be a singleton path of type TabEdge" )
99+ . unwrap_basic ( ) ;
82100 migrated_model. add_mor (
83101 nl. clone ( ) ,
84102 model. mor_generator_dom ( & nl) . unwrap_basic ( ) ,
85- model . mor_generator_cod ( & nl ) . unwrap_basic ( ) ,
103+ nl_cod ,
86104 name ( "Negative" ) . into ( ) ,
87105 ) ;
88106 }
89107
90108 migrated_model
91109}
92110
93- // TO-DO: add test !
94111#[ cfg( test) ]
95112mod tests {
96113 use super :: * ;
97114 use crate :: dbl:: model:: MutDblModel ;
98- use crate :: stdlib:: { negative_backward_link} ;
115+ use crate :: stdlib:: negative_backward_link;
99116 use std:: rc:: Rc ;
100117
101118 #[ test]
@@ -115,7 +132,6 @@ mod tests {
115132 cld_model. add_mor ( name ( "link" ) , name ( "y" ) , name ( "f" ) , name ( "Negative" ) . into ( ) ) ;
116133
117134 // Test the putative migration against the correct one
118- // TO-DO: I don't think you can use assert_eq!() on models?
119135 assert_eq ! ( span_migrate( sf_model) , cld_model) ;
120136 }
121137}
0 commit comments