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
- Finalizing updates to all the new constraints with a write up in the scheduler README, in order
- Deleted all of Ryan's old constraints that I figured didn't apply any more (either didn't make sense, or were redundant)
- Kept the numbering scheme the same for now
- Need to address a problem in the future (probably) regarding the duration of tasks that have the same asset
# 0) Total number of assignments needs to be less than or equal to the number of periods available
273
-
'''
274
-
the sum of the total amount of periods assigned to tasks cannot be more than the total number of periods available:
275
-
(Xtp_00 + ... + Xtp_TP) <= P
276
-
'''
277
-
278
-
# TODO: I dont know if this is necessary
279
-
280
-
"""
281
-
# 1 row
282
-
A_ub_0 = np.zeros((1, num_variables), dtype=int) # Every period assigned to a task counts as 1 towards the total assigned periods. This assumes one pair per period
283
-
b_ub_0 = np.array([self.P], dtype=int)
284
-
285
-
# Set the coefficients for the Xtp variables to 1
286
-
A_ub_0[0, self.Xtp_start:self.Xtp_end] = 1
287
-
288
-
if wordy > 1:
289
-
print("A_ub_0^T:")
290
-
for i in range(self.Xtp_start, self.Xtp_end):
291
-
pstring = str(self.X_indices[i])
292
-
for column in A_ub_0.transpose()[i]:
293
-
pstring += f"{ column:5}"
294
-
print(pstring)
295
-
print("b_ub_0: ", b_ub_0)
296
-
297
-
A_ub_list.append(A_ub_0)
298
-
b_ub_list.append(b_ub_0)
299
-
300
-
if wordy > 0:
301
-
print("Constraint 0 built.")
302
-
"""
303
272
# 1) asset can only be assigned to a task if asset is capable of performing the task (value of pairing is non-negative)
304
273
'''
305
274
if task t cannot be performed by asset a, then Xta_ta = 0
A_lb_5[t, (self.Xtp_start + t * self.P):(self.Xtp_start + t * self.P + self.P)] = 1 # Set the coefficients for the Xtp variables to 1 for each task t
624
-
625
-
if wordy > 1:
626
-
print("A_lb_5^T:")
627
-
print(" T1 T2") # Header for 2 tasks
628
-
for i in range(self.Xtp_start,self.Xtp_end):
629
-
pstring = str(self.X_indices[i])
630
-
for column in A_lb_5.transpose()[i]:
631
-
pstring += f"{ column:5}"
632
-
print(pstring)
633
-
print("b_lb_5: ", b_lb_5)
634
-
635
-
A_lb_list.append(A_lb_5)
636
-
b_lb_list.append(b_lb_5)
637
-
638
-
if wordy > 0:
639
-
print("Constraint 5 built.")
640
-
"""
641
-
# 6) The total number of assets assigned cannot be greater than the number of assets available but must be greater than the number of tasks.
642
-
'''
643
-
Sum of all asset-period pairs must be >= T:
644
-
645
-
A >= (Xap_00 + ... + Xap_AP) >= T
646
-
'''
647
-
"""
648
-
A_6 = np.zeros((1, num_variables), dtype=int)
649
-
b_lb_6 = np.array([self.T], dtype=int)
650
-
b_ub_6 = np.array([self.A], dtype=int)
651
-
652
-
A_6[0,self.Xap_start:self.Xap_end] = 1
653
-
654
-
if wordy > 1:
655
-
print("A_6^T:")
656
-
for i in range(self.Xap_start,self.Xap_end):
657
-
pstring = str(self.X_indices[i])
658
-
for column in A_6.transpose()[i]:
659
-
pstring += f"{ column:5}"
660
-
print(pstring)
661
-
print("b_lb_6: ", b_lb_6)
662
-
print("b_ub_6: ", b_ub_6)
663
-
664
-
A_lb_list.append(A_6)
665
-
b_lb_list.append(b_lb_6)
666
-
A_ub_list.append(A_6)
667
-
b_ub_list.append(b_ub_6)
668
-
669
-
if wordy > 0:
670
-
print("Constraint 6 built.")
671
-
672
-
# 7) Ensure tasks are assigned as early as possible
673
-
'''
674
-
A task cannot be assigned if it could have been assigned in an earlier period.
675
-
This encourages the solver to assign tasks to the earliest possible periods.
676
-
677
-
Practical implementation: Rather than hard constraints (which can cause infeasibility),
678
-
we add this preference to the objective function by giving later start times
679
-
higher costs. This encourages early scheduling without making the problem infeasible.
680
-
'''
681
-
682
-
# No hard constraints for Constraint 7 - implemented in objective function
683
-
# The preference for earlier start times will be added as small penalties
684
-
# in the objective function coefficients for Xts variables
685
-
686
-
if wordy > 0:
687
-
print("Constraint 7 built (implemented as objective function preference).")
688
-
689
-
"""
690
-
# 7) Ensure tasks are assigned as early as possible
691
-
'''
692
-
A task cannot be assigned if it could have been assigned in an earlier period. This encourages the solver to assign tasks to the earliest possible periods.
693
-
'''
694
-
695
-
# 8) All tasks must be assigned to at least one time period
696
-
'''
697
-
698
-
The sum of all task-period decision variables for each task must be greater than 1, indicating all tasks were assigned at least once:
A_lb_13[p, (self.Xap_start + p * self.A):(self.Xap_start + p * self.A + self.A)] = 1
887
-
A_lb_13[p, (self.Xtp_start + p):(self.Xtp_start + p + self.P)] = 1
888
-
889
-
if wordy > 1:
890
-
print("A_lb_13^T:")
891
-
print(" P1 P2 P3 P4 P5") # Header for 5 periods
892
-
for i in range(self.Xtp_start,self.Xap_end):
893
-
pstring = str(self.X_indices[i])
894
-
for column in A_lb_13.transpose()[i]:
895
-
pstring += f"{ column:5}"
896
-
print(pstring)
897
-
print("b_lb_13: ", b_lb_13)
898
-
899
-
A_lb_list.append(A_lb_13)
900
-
b_lb_list.append(b_lb_13)
901
-
902
-
if wordy > 0:
903
-
print("Constraint 13 built.")
904
-
"""
905
721
# 14) if a task-starttime pair is selected, the corresponding task-period pair must be selected for the period equal to the start time plus the duration of the task
906
722
'''
907
723
This ensures that if a task is assigned a start time, the corresponding task-period pair for the period equal to the start time plus the duration of the task is also selected.
0 commit comments