@@ -215,11 +215,11 @@ impl PetriNetMassActionAnalysis {
215215pub struct StockFlowMassActionAnalysis {
216216 /// Object type for stocks.
217217 pub stock_ob_type : TabObType ,
218- /// Morphism types for flows between stocks.
218+ /// Morphism type for flows between stocks.
219219 pub flow_mor_type : TabMorType ,
220- /// Morphism types for links for stocks to flows.
220+ /// Morphism type for positive links from stocks to flows.
221221 pub pos_link_mor_type : TabMorType ,
222- /// Morphism types for links for stocks to flows.
222+ /// Morphism type for negative links from stocks to flows.
223223 pub neg_link_mor_type : TabMorType ,
224224}
225225
@@ -250,32 +250,25 @@ impl StockFlowMassActionAnalysis {
250250 } )
251251 . collect ( ) ;
252252
253- for link in model . mor_generators_with_type ( & self . pos_link_mor_type ) {
253+ let mut multiply_for_link = | link : QualifiedName , exponent : i8 | {
254254 let dom = model. mor_generator_dom ( & link) . unwrap_basic ( ) ;
255255 let path = model. mor_generator_cod ( & link) . unwrap_tabulated ( ) ;
256256 let Some ( TabEdge :: Basic ( cod) ) = path. only ( ) else {
257257 panic ! ( "Codomain of link should be basic morphism" ) ;
258258 } ;
259259 if let Some ( term) = terms. get_mut ( & cod) {
260- let mon: Monomial < _ , i8 > = [ ( dom, 1 ) ] . into_iter ( ) . collect ( ) ;
260+ let mon: Monomial < _ , i8 > = [ ( dom, exponent ) ] . into_iter ( ) . collect ( ) ;
261261 * term = std:: mem:: take ( term) * mon;
262262 } else {
263263 panic ! ( "Codomain of link does not belong to model" ) ;
264264 } ;
265- }
265+ } ;
266266
267+ for link in model. mor_generators_with_type ( & self . pos_link_mor_type ) {
268+ multiply_for_link ( link, 1 ) ;
269+ }
267270 for link in model. mor_generators_with_type ( & self . neg_link_mor_type ) {
268- let dom = model. mor_generator_dom ( & link) . unwrap_basic ( ) ;
269- let path = model. mor_generator_cod ( & link) . unwrap_tabulated ( ) ;
270- let Some ( TabEdge :: Basic ( cod) ) = path. only ( ) else {
271- panic ! ( "Codomain of link should be basic morphism" ) ;
272- } ;
273- if let Some ( term) = terms. get_mut ( & cod) {
274- let mon: Monomial < _ , i8 > = [ ( dom, -1 ) ] . into_iter ( ) . collect ( ) ;
275- * term = std:: mem:: take ( term) * mon;
276- } else {
277- panic ! ( "Codomain of link does not belong to model" ) ;
278- } ;
271+ multiply_for_link ( link, -1 ) ;
279272 }
280273
281274 let terms: Vec < _ > = terms
0 commit comments