Skip to content

Commit 9018f79

Browse files
committed
Scheduler.py console printing improvements:
- Adds printing of the constraint matrix for each constraint if wordy = 2 - Additional printing possible with wordy = 3 - Wordy = 0 disables all printing - Fixes typo in docs for constriant 2
1 parent 118cd02 commit 9018f79

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

famodel/irma/scheduler.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import numpy as np
2525
import os
2626

27-
wordy = 1 # level of verbosity for print statements
27+
wordy = 2 # level of verbosity for print statements
2828

2929
class Scheduler:
3030

@@ -255,6 +255,15 @@ def set_up_optimizer(self, goal : str = "cost"):
255255
A_ub_0 = np.ones((1, len(decision_vars)), dtype=int) # Every period assigned to a task counts as 1 towards the total assigned periods. This assumes one pair per period
256256
b_ub_0 = np.array([self.num_periods])
257257

258+
if wordy > 1:
259+
print("A_ub_0^T:")
260+
for i in range(A_ub_0.transpose().shape[0]):
261+
pstring = str(self.x_indices[i])
262+
for column in A_ub_0.transpose()[i]:
263+
pstring += f"{ column:5}"
264+
print(pstring)
265+
print("b_ub_0: ", b_ub_0)
266+
258267
A_ub_list.append(A_ub_0)
259268
b_ub_list.append(b_ub_0)
260269

@@ -282,9 +291,21 @@ def set_up_optimizer(self, goal : str = "cost"):
282291
for i in range(len(self.x_indices)):
283292
print(f" {self.x_indices[i]}: {A_eq_1[0, i]}")
284293

294+
if wordy > 1:
295+
print("A_eq_1^T:")
296+
for i in range(A_eq_1.transpose().shape[0]):
297+
pstring = str(self.x_indices[i])
298+
for column in A_eq_1.transpose()[i]:
299+
pstring += f"{ column:5}"
300+
print(pstring)
301+
print("b_eq_1: ", b_eq_1)
302+
285303
A_eq_list.append(A_eq_1)
286304
b_eq_list.append(b_eq_1)
287305

306+
if wordy > 0:
307+
print("Constraint 1 built.")
308+
288309
# 2) task dependencies must be respected (i.e., a task cannot start until all its dependencies have been satisfied)
289310
# '''
290311
# This enforces task dependencies by ensuring that a task can only be assigned to a time period if all its dependencies have been completed in previous periods.
@@ -325,7 +346,7 @@ def set_up_optimizer(self, goal : str = "cost"):
325346
# A_lb_2[index, :] = mask.flatten()
326347
# index += 1
327348

328-
# if wordy > 2:
349+
# if wordy > 1:
329350
# print("A_lb_2^T:")
330351
# print(" T1 T2 ") # Header for 2 tasks
331352
# for i in range(A_lb_2.transpose().shape[0]):
@@ -366,9 +387,9 @@ def set_up_optimizer(self, goal : str = "cost"):
366387
A_ub_4[index, :] = mask.flatten()
367388
index += 1
368389

369-
if wordy > 2:
390+
if wordy > 1:
370391
print("A_ub_4^T:")
371-
print(" P1A1 P1A2 P2A1") # Header for 2 tasks and 2 assets example with T2A2 invalid
392+
print(" P1A1 P1A2 P2A1 P2A2 P3A1 P3A2 P4A1 P4A2 P5A1 P5A2") # header for 5 periods and 2 assets example
372393
for i in range(A_ub_4.transpose().shape[0]):
373394
pstring = str(self.x_indices[i])
374395
for column in A_ub_4.transpose()[i]:
@@ -420,6 +441,16 @@ def set_up_optimizer(self, goal : str = "cost"):
420441
for i in range(len(self.x_indices)):
421442
print(f" {self.x_indices[i]}: {A_lb_8[t, i]}")
422443

444+
if wordy > 1:
445+
print("A_lb_8^T:")
446+
print(" T1 T2") # Header for 2 tasks
447+
for i in range(A_lb_8.transpose().shape[0]):
448+
pstring = str(self.x_indices[i])
449+
for column in A_lb_8.transpose()[i]:
450+
pstring += f"{ column:5}"
451+
print(pstring)
452+
print("b_lb_8: ", b_lb_8)
453+
423454
A_lb_list.append(A_lb_8)
424455
b_lb_list.append(b_lb_8)
425456

@@ -455,7 +486,7 @@ def set_up_optimizer(self, goal : str = "cost"):
455486
# A_eq_9[pair_i, :] = mask.flatten()
456487
# pair_i += 1
457488

458-
# if wordy > 0:
489+
# if wordy > 1:
459490
# # Print out the constraint matrix for debugging
460491
# print("A_eq_9^T:")
461492
# print(" T1A1 T1A2 T2A1") # Header for 2 tasks and 2 assets example with T2A2 invalid
@@ -502,6 +533,17 @@ def set_up_optimizer(self, goal : str = "cost"):
502533
print(f" {self.x_indices[i]}: {A_ub_10[p, i]}")
503534
print("Upper bound limit: ", b_ub_10[p])
504535

536+
537+
if wordy > 1:
538+
print("A_ub_10^T:")
539+
print(" P1 P2 P3 P4 P5") # Header for 5 periods
540+
for i in range(A_ub_10.transpose().shape[0]):
541+
pstring = str(self.x_indices[i])
542+
for column in A_ub_10.transpose()[i]:
543+
pstring += f"{ column:5}"
544+
print(pstring)
545+
print("b_ub_10: ", b_ub_10)
546+
505547
A_ub_list.append(A_ub_10)
506548
b_ub_list.append(b_ub_10)
507549

famodel/irma/schedulerREADME.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $$
4040
### 2. Task Dependencies (**Disabled/In-progress**)
4141
Tasks with dependencies must be scheduled after their dependencies are completed. This might need to be reworked, still figuring out the best way to enforce temporal constraints.
4242
$$
43-
p * x_{p,r,a} < p * x_{p,t,a} \quad t \in T, \forall r \in R_t, p \in P, a \in A
43+
p * x_{p,r,a} + d_r < p * x_{p,t,a} \quad t \in T, \forall r \in R_t, p \in P, a \in A
4444
$$
4545

4646
### 3. Weather Constraints (**TODO**)

0 commit comments

Comments
 (0)