Skip to content

Commit 1a2bee4

Browse files
committed
Adds get_row function to tasks:
- get_row function structure added to task class - get_row returns a len(assets)x2 array of zeros for runability of code. This will need to be changed with a real calcualtion of costs and durations - Irma constructs a task asset matrix by adding up these rows - The task asset matrix built by irma is rows = tasks, columns = assets
1 parent 9786637 commit 1a2bee4

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

famodel/irma/irma.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,9 @@ def findCompatibleVessels(self):
436436

437437

438438
# ----- Generate tasks (groups of Actions according to specific strategies) -----
439-
439+
tasks = []
440440
t1 = Task(sc.actions, 'install_mooring_system')
441+
tasks.append(t1)
441442

442443
# ----- Do some graph analysis -----
443444

@@ -455,8 +456,17 @@ def findCompatibleVessels(self):
455456
for akey, anchor in project.anchorList.items():
456457
for a in anchor.install_dependencies: # go through required actions (should just be the anchor install)
457458
a.evaluateAssets({'carrier' : sc.vessels["MPSV_01"]}) # see if this example vessel can do it
458-
459-
459+
460+
461+
# ----- Generate the task_asset_matrix for scheduler -----
462+
# UNUSED FOR NOW
463+
task_asset_matrix = np.zeros((len(tasks), len(sc.vessels), 2))
464+
for i, task in enumerate(tasks):
465+
row = task.get_row(sc.vessels)
466+
if row.shape != (len(sc.vessels), 2):
467+
raise Exception(f"Task '{task.name}' get_row output has wrong shape {row.shape}, should be {(2, len(sc.vessels))}")
468+
task_asset_matrix[i, :] = row
469+
460470
# ----- Call the scheduler -----
461471
# for timing with weather windows and vessel assignments
462472

famodel/irma/task.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,38 @@ def getTaskGraph(self):
9292
longest_path = nx.dag_longest_path(G, weight='duration')
9393
longest_path_edges = list(zip(longest_path, longest_path[1:])) # Convert path into edge pairs
9494
total_duration = sum(self.actionList[node].duration for node in longest_path)
95-
return G
95+
return G
96+
97+
def get_row(self, assets):
98+
'''Get a matrix of (cost, duration) tuples for each asset to perform this task. Will be a row in the task_asset matrix.
99+
100+
Parameters
101+
----------
102+
assets : list
103+
A list of all assets available to perform the task.
104+
105+
Returns
106+
-------
107+
matrix : array-like
108+
A 2D array of (cost, duration) tuples indicating the cost and duration for each asset to perform this task.
109+
Must be 2x len(assets).
110+
111+
'''
112+
113+
matrix = np.zeros((len(assets), 2))
114+
# TODO: build row of matrix that holds (cost, duration) tuple of asset / assets (?) to complete task
115+
116+
# Could look something like...
117+
'''
118+
for i, asset in enumerate(assets):
119+
for action in self.actionList: # can we do this without the double loop?
120+
if asset in action.roles:
121+
action = self.actionList[asset.name]
122+
matrix[i, 0] = action.cost
123+
matrix[i, 1] = action.duration
124+
else:
125+
matrix[i, 0] = -1 # negative cost/duration means asset cannot perform task
126+
matrix[i, 1] = -1
127+
'''
128+
129+
return np.zeros((len(assets), 2)) # placeholder, replace with actual matrix

0 commit comments

Comments
 (0)