@@ -198,10 +198,11 @@ def registerAction(self, action):
198198
199199 # this also handles creation of unique dictionary keys
200200
201- while action .name in self .actions : # check if there is already a key with the same name
201+ if action .name in self .actions : # check if there is already a key with the same name
202+ raise Warning (f"Action '{ action .name } ' is already registered." )
202203 print (f"Action name '{ action .name } ' is in the actions list so incrementing it..." )
203204 action .name = increment_name (action .name )
204-
205+
205206 # What about handling of dependencies?? <<< done in the action object,
206207 # but could check that each is in the list already...
207208 for dep in action .dependencies .values ():
@@ -275,6 +276,16 @@ def visualizeActions(self):
275276 plt .text (pos [last_node ][0 ], pos [last_node ][1 ] - 0.1 , f"{ total_duration :.2f} hr" , fontsize = 12 , color = 'red' , fontweight = 'bold' , ha = 'center' )
276277 else :
277278 pass
279+ plt .axis ('equal' )
280+
281+ # Color first node (without dependencies) green
282+ i = 0
283+ for node in G .nodes ():
284+ if G .in_degree (node ) == 0 : # Check if the node has no incoming edges
285+ nx .draw_networkx_nodes (G , pos , nodelist = [node ], node_color = 'green' , node_size = 500 , label = 'Action starters' if i == 0 else None )
286+ i += 1
287+ plt .legend ()
288+ return G
278289
279290
280291
@@ -326,38 +337,38 @@ def findCompatibleVessels(self):
326337
327338 # Parse out the install steps required
328339
329- for anchor in project .anchorList .values ():
340+ for akey , anchor in project .anchorList .items ():
330341
331342 # add and register anchor install action(s)
332- a1 = sc .addAction ('install_anchor' , 'install_anchor-1 ' , objects = [anchor ])
333- a1 .evaluateAssets ({'operator ' : sc .vessels ["MPSV_01" ]}) # example assignment to test the code.
343+ a1 = sc .addAction ('install_anchor' , f 'install_anchor-{ akey } ' , objects = [anchor ])
344+ a1 .evaluateAssets ({'carrier ' : sc .vessels ["MPSV_01" ]})
334345
335346 # register the actions as necessary for the anchor <<< do this for all objects??
336347 anchor .install_dependencies = [a1 ]
337348
338349
339350 hookups = [] # list of hookup actions
340351
341- for mooring in project .mooringList .values ():
352+ for mkey , mooring in project .mooringList .items ():
342353
343354 # note origin and destination
344355
345356 # --- lay out all the mooring's actions (and their links)
346357 # create load vessel action
347- a2 = sc .addAction ('load_mooring' , 'load_mooring' , objects = [mooring ])
358+ a2 = sc .addAction ('load_mooring' , f 'load_mooring- { mkey } ' , objects = [mooring ])
348359
349360 # create ship out mooring action
350361
351362 # create lay mooring action
352- a3 = sc .addAction ('lay_mooring' , 'lay_mooring' , objects = [mooring ], dependencies = [a2 ])
363+ a3 = sc .addAction ('lay_mooring' , f 'lay_mooring- { mkey } ' , objects = [mooring ], dependencies = [a2 ])
353364 sc . addActionDependencies (a3 , mooring .attached_to [0 ].install_dependencies ) # in case of shared anchor
354365
355366 # mooring could be attached to anchor here - or could be lowered with anchor!!
356367 #(r=r_anch, mooring=mooring, anchor=mooring.anchor...)
357368 # the action creator can record any dependencies related to actions of the anchor
358369
359370 # create hookup action
360- a4 = sc .addAction ('mooring_hookup' , 'mooring_hookup' ,
371+ a4 = sc .addAction ('mooring_hookup' , f 'mooring_hookup- { mkey } ' ,
361372 objects = [mooring , mooring .attached_to [1 ]], dependencies = [a2 , a3 ])
362373 #(r=r, mooring=mooring, platform=platform, depends_on=[a4])
363374 # the action creator can record any dependencies related to actions of the platform
@@ -374,7 +385,7 @@ def findCompatibleVessels(self):
374385
375386 # ----- Do some graph analysis -----
376387
377- sc .visualizeActions ()
388+ G = sc .visualizeActions ()
378389
379390
380391
0 commit comments