Skip to content

Commit 463232a

Browse files
committed
add lower bound as a feature
1 parent 077af7f commit 463232a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

model/graph.py

-3
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ def __init__(self, device: str):
226226
self.operation_resource_time: list[list[list[int]]] = []
227227
self.approximate_design_load: list[list[int]] = []
228228
self.approximate_physical_load: list[list[int]] = []
229-
230-
self.item_possible = []
231-
self.operation_possible = []
232229

233230
self.graph: HeteroData = HeteroData()
234231
self.device: str = device

translators/instance2graph_translator.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@ def build_item(i: Instance, graph: GraphInstance, p: int, e: int, head: bool, es
4545
pr_ids: list = []
4646
pm_ids: list = []
4747
for o in range(start, end):
48-
if o > start:
49-
op_start = op_start+operation_mean_time
50-
else:
51-
op_start = estimated_start
5248
succs = end-(o+1)
5349
operation_load = i.operation_time(p,o, total_load=True)
54-
operation_mean_time = i.operation_time(p,o, total_load=False)
5550
required_res = 0
5651
required_mat = 0
5752
for rt in i.required_rt(p, o):
@@ -99,15 +94,15 @@ def build_item(i: Instance, graph: GraphInstance, p: int, e: int, head: bool, es
9994
estimated_childrend_end = _base_design_end
10095
estimated_children_cost = 0
10196
for children in graph.direct_children[p][e]:
102-
graph, child_id, estimated_end_child, child_cost = build_item(i, graph, p, e=children, head=False, estimated_start=estimated_start_child, must_be_outsourced=must_be_outsourced)
97+
child_id, estimated_end_child, child_cost = build_item(i, graph, p, e=children, head=False, estimated_start=estimated_start_child, must_be_outsourced=must_be_outsourced)
10398
graph.add_item_assembly(item_id, child_id)
10499
estimated_childrend_end = max(estimated_childrend_end, estimated_end_child)
105100
estimated_children_cost += child_cost
106101
external_end = estimated_start + i.outsourcing_time[p][e]
107102
internal_end = estimated_childrend_end + physical_mean_time
108103
estimated_end = external_end if must_be_outsourced else min(external_end, internal_end) if i.external[p][e] else internal_end
109104
mandatory_cost = estimated_children_cost + (i.external_cost[p][e] if must_be_outsourced else 0)
110-
return graph, item_id, estimated_end, mandatory_cost
105+
return item_id, estimated_end, mandatory_cost
111106

112107
def build_precedence(i: Instance, graph: GraphInstance):
113108
for p in i.loop_projects():
@@ -133,7 +128,6 @@ def build_precedence(i: Instance, graph: GraphInstance):
133128
for pfp in parent_first_physical:
134129
succ_id = graph.operations_i2g[p][pfp]
135130
graph.add_precedence(o_id, succ_id)
136-
return graph
137131

138132
def build_direct_access_objects(i: Instance, graph: GraphInstance):
139133
for p in i.loop_projects():
@@ -164,11 +158,20 @@ def build_direct_access_objects(i: Instance, graph: GraphInstance):
164158
graph.operation_resource_time[p][o].append(i.operation_resource_time(p, o, rt, max_load=True))
165159
for r in i.loop_resources():
166160
graph.resource_family.append(i.get_resource_familly(r))
167-
return graph
161+
162+
def rec_lower_bound(i: Instance, graph: GraphInstance, p: int, o: int, start: int, next_operations: list[list[list[int]]]):
163+
graph.update_operation(graph.operations_i2g[p][o], [('lb', start)], maxx=True)
164+
for next in next_operations[p][o]:
165+
rec_lower_bound(i, graph, p, next, start + i.operation_time(p, o, total_load=False), next_operations)
166+
167+
def build_lower_bounds(i: Instance, graph: GraphInstance, next_operations: list[list[list[int]]]):
168+
for p in i.loop_projects():
169+
for o in i.first_operations(p, i.project_head(p)):
170+
rec_lower_bound(i, graph, p, o, 0, next_operations)
168171

169172
def translate(i: Instance, device: str):
170173
graph = GraphInstance(device=device)
171-
graph = build_direct_access_objects(i, graph)
174+
build_direct_access_objects(i, graph)
172175
for rt in range(i.nb_resource_types):
173176
resources = i.resources_by_type(rt)
174177
operations = i.operations_by_resource_type(rt)
@@ -195,14 +198,15 @@ def translate(i: Instance, device: str):
195198
Cmax_lower_bound = 0
196199
cost_lower_bound = 0
197200
for p in i.loop_projects():
198-
graph, _, project_end, project_cost = build_item(i, graph, p, e=i.project_head(p), head=True, estimated_start=0, must_be_outsourced=False)
201+
_, project_end, project_cost = build_item(i, graph, p, e=i.project_head(p), head=True, estimated_start=0, must_be_outsourced=False)
199202
Cmax_lower_bound = max(Cmax_lower_bound, project_end)
200203
cost_lower_bound += project_cost
201204
graph.operations_i2g = graph.build_i2g_2D(graph.operations_g2i)
202205
graph.items_i2g = graph.build_i2g_2D(graph.items_g2i)
203206
graph.add_dummy_item(device=device)
204-
graph = build_precedence(i, graph)
207+
build_precedence(i, graph)
205208
previous_operations, next_operations = i.build_next_and_previous_operations()
209+
build_lower_bounds(i, graph, next_operations)
206210
related_items: Tensor = graph.flatten_related_items(device)
207211
parent_items: Tensor = graph.flatten_parents(device)
208212
return graph, Cmax_lower_bound, cost_lower_bound, previous_operations, next_operations, related_items, parent_items

0 commit comments

Comments
 (0)