Originally posted by: JJC_UAB
Hi Petr,
Yes, it is a homework. We have to complete the code without modify the other parts. And the makespam should be less than the original problem.
The question is:
Extend your model from Exercise 1 to enable several machine units of
the same resource type. The new required data set and structures are given to you in
the data file and jobScheduling model template respectively.
Neither data sets nor data structures should be modified. You must complete the
decision variable declarations and adapt the constraints from Exercise 1 and add the
new constraint as indicated in the model template.
using CP;
{string} ComputerTypes = ...;
{string} ActivityTypes = ...;
{string} ResourceTypes = ...;
// Production work orders
int requiredQuantities[ComputerTypes] = ...;
/*************************************************
* An activity consists of
* - an activity type,
* - a duration,
* - a unary resource requirement, and
* - a list of precedences.
*************************************************/
tuple ActivityData {
key string name;
int duration;
string requirement;
{string} precedences;
};
{ActivityData} activities[ComputerTypes] = ...;
/********************************************************
* Each particular activity for each computer consist of:
* - a defined activity
* - for a computer type
* - for each computer to be manufatured
********************************************************/
tuple ComputerActivityMatch {
ActivityData activity;
string computerType;
int computer;
};
// All activities that must get scheduled
{ComputerActivityMatch} allActivities = {<a,c,j> | c in ComputerTypes,
a in activities[c],
j in 1..requiredQuantities[c]};
// The activities which must precede an activity
{ComputerActivityMatch} precedences[a in allActivities] = { b | b in allActivities :
a.computerType == b.computerType &&
a.computer == b.computer &&
b.activity.name in a.activity.precedences };
/********************************************************
* Resource data consists of:
* - ResourceType
* - Number of available resorces of this type
*******************************************************/
tuple ResourceData {
key string resourceType;
int available;
}
// for describing each resource (machine)
tuple ResourceUnit{
string resourceType;
int unit;
}
/*************************************
* Reads the defined resource units
* for each resource type
*************************************/
{ResourceData} resources = ...;
{ResourceUnit} availableResources = {<r.resourceType, i> | r in resources, i in 1..r.available};
/**********************************************
* Represent the pairs activity<->resouce unit
**********************************************/
tuple JobAllocation {
ComputerActivityMatch job;
int machineId;
}
/*********************************************
* Define the domain for the different
* choices when assigning a job to a machine
*********************************************/
{JobAllocation} jobAllocations = {<job, unit> |
job in allActivities, r in resources, unit in 1..r.available : job.activity.requirement == r.resourceType};
dvar interval activity[a in allActivities] size a.activity.duration;
dvar interval jobAllocation [j in jobAllocations] optional size j.job.activity.duration; // complete the dvar declaration accordingly
dvar sequence resource[r in availableResources] in
all(a in allActivities: a.activity.requirement==r.resourceType) activity[a]; // complete the dvar declaration accordingly
// Constraints labels
constraint Precedence[allActivities,allActivities];
execute {
cp.param.FailLimit = 10000;
}
dexpr int makespan = max(a in allActivities) endOf(activity[a]);// Complete makespan expression;
minimize makespan;
subject to {
// Remove symmetry
forall(a1,a2 in allActivities:
(a1.activity == a2.activity &&
a1.computerType == a2.computerType &&
a1.computer < a2.computer) )
BreakSymmetry: endBeforeStart(activity[a1], activity[a2]);
// Each activity is performed only once
// Resource Requirements
forall (r in availableResources)
NoOverlap: noOverlap(resource[r]);
// Precedences
forall( a in allActivities)
forall( p in precedences[a])
Precedence[a,p]: endBeforeStart(activity[p], activity[a]);
};
#DecisionOptimization#OPLusingCPOptimizer