This project is a soft constrained “Python Tutorial 5”(../chapter10).
import sc3
import itertools
for person in A_Member_in_All:
vlist=[]
s='Python Paid Holiday'+' '+staffdef[person]+'\n'
for day in Mon:
v=sc3.GetShiftVar(person,day,'Paid_Holiday')
vlist.append(v)
sc3.AddSoft(vlist[0] | vlist[1] | vlist[2] | vlist[3] | vlist[4],s,4)#soft_level 4
for v in itertools.combinations(vlist,2):
sc3.AddSoft(v[0] | v[1],s,4)#soft level 4import sc3
sc3.AddSoft(variable ,string ,soft_level)
is the format of the soft constraint. soft_level must be a constant.
AddSoft expects variable to be True; if it is True, it is not counted; if it is False, it is counted;
The optimal system works to minimize the total system cost.
When initially set, the checkbox for the soft level in the Solve Table, so check it to solve the problem.