You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Markdown plaintext in function descriptions for action.py. Adds assignAsset which is called by assignAssets for each {role : asset} pair. Sets up structure for checking different asset combinations for action. Removes requirements from actions.yaml.
self.duration=getFromDict(actionType, 'duration', default=0) # this will be overwritten by calcDurationAndCost. TODO: or should it overwrite any duration calculation?
128
+
self.cost=0# this will be overwritten by calcDurationAndCost
128
129
129
130
self.supported_objects= [] # list of FAModel object types supported by the action
self.assets[role_name] =asset# Assignment required for calcDurationAndCost(), will be cleared later
391
+
else:
392
+
print('INFO: '+message+' Action cannot be completed by provided asset list.')
393
+
return-1, -1# return negative values to indicate incompatibility. Loop is terminated becasue assets not compatible for roles.
410
394
395
+
# Check that all roles in the action are filled
396
+
forrole_nameinself.requirements.keys():
397
+
ifself.assets[role_name] isNone:
398
+
399
+
forrole_nameinassets.keys(): # Clear the assets dictionary
400
+
assets[role_name] =None
401
+
raiseException(f"Role '{role_name}' is not filled in action '{self.name}'. Cannot calculate duration and cost.") # possibly just a warning and not an exception?
402
+
403
+
404
+
duration, cost=self.calcDurationAndCost()
405
+
406
+
forrole_nameinassets.keys(): # Clear the assets dictionary
407
+
assets[role_name] =None
408
+
409
+
returnduration, cost# values returned here rather than set because will be used to check compatibility and not set properties of action
410
+
411
+
412
+
defassignAsset(self, role_name, asset):
413
+
'''
414
+
Checks if asset can be assigned to an action.
415
+
If yes, assigns asset to role in the action.
416
+
417
+
Inputs
418
+
------
419
+
`role_name` : `str`
420
+
The name of the role to which the asset will be assigned.
421
+
`asset` : `dict`
422
+
The asset to be assigned to the role.
423
+
424
+
Returns
425
+
-------
426
+
`None`
427
+
'''
428
+
# Make sure role_name is valid for this action
429
+
ifnotrole_nameinself.assets.keys():
430
+
raiseException(f"The specified role name '{role_name}' is not in this action.")
Assigns assets to all the roles in the action. This calls
441
+
`assignAsset()` for each role/asset pair and then calculates the
442
+
duration and cost for the action. Similar to `evaluateAssets()`
443
+
however here assets are assigned and duration and cost are
444
+
set after evaluation.
445
+
446
+
Inputs
447
+
------
448
+
`assets` : `dict`
449
+
Dictionary of {role_name: asset} pairs for assignment of the
450
+
assets to the roles in the action.
451
+
452
+
Returns
453
+
-------
454
+
`None`
455
+
'''
411
456
412
-
# can store the cost and duration in self as well
457
+
# Assign each specified asset to its respective role
458
+
forrole_name, assetinassets.items():
459
+
self.assignAsset(role_name, asset)
413
460
461
+
# Check that all roles in the action are filled
462
+
forrole_nameinself.requirements.keys():
463
+
ifself.assets[role_name] isNone:
464
+
raiseException(f"Role '{role_name}' is not filled in action '{self.name}'. Cannot calculate duration and cost.") # possibly just a warning and not an exception?
465
+
466
+
self.calcDurationAndCost()
414
467
415
468
416
469
# ----- Below are drafts of methods for use by the engine -----
@@ -421,11 +474,11 @@ def begin(self):
421
474
422
475
Inputs
423
476
------
424
-
None
477
+
`None`
425
478
426
479
Returns
427
480
-------
428
-
None
481
+
`None`
429
482
'''
430
483
for vessel in self.vesselList:
431
484
vessel._attach_to(self)
@@ -439,11 +492,11 @@ def end(self):
439
492
440
493
Inputs
441
494
------
442
-
None
495
+
`None`
443
496
444
497
Returns
445
498
-------
446
-
None
499
+
`None`
447
500
'''
448
501
for vessel in self.vesselList:
449
502
vessel._detach_from()
@@ -457,11 +510,11 @@ def timestep(self):
457
510
458
511
Inputs
459
512
------
460
-
None
513
+
`None`
461
514
462
515
Returns
463
516
-------
464
-
None
517
+
`None`
465
518
'''
466
519
467
520
# (this is just documenting an idea for possible future implementation)
0 commit comments