Originally posted by: adelalb
Philippe,
I'm still struggling with this. I have been following an example from the tutorial and not sure what went wrong with this.
Data File
SheetConnection file ( "..\\Data\\DModel21616try9.xls" );
// Step 1: Feasible Schedule
Tasks from SheetRead (file, "Tasks!A2:E12");
TopLevelTask from SheetRead (file, "Tasks!A2");
ParentLinks from SheetRead (file, "Hierarchy!A2:B11");
Precedences from SheetRead (file, "Precedences!A2:D8");
//Step 2: Assignments of Pesonnel Resources to Activities
Capabilities from SheetRead (file, "Capabilities!A2:B2");
Workers from SheetRead (file, "Workers!A2:D7");
Proficiencies from SheetRead (file, "Proficiencies!A2:C7");
Requirements from SheetRead (file, "Requirements!A2:C17");
RequiredCapabilities from SheetRead (file, "RequiredCapabilities!A2:E17");
using CP;
/********
* Data *
********/
//--------------------------------------Tasks
tuple Task {
key int id;
string name;
int ptMin;
int Cont_Max;
int Cont_Min;
};
{ Task } Tasks = ...;
int TopLevelTask = ...;
//-----------------------------------hierarchy data
tuple ParentLink {
int taskId;
int parentId;
};
{ ParentLink } ParentLinks = ...;
{ int } Parents = { p.parentId | p in ParentLinks };
//-----------------------------------Precedence
tuple Precedence {
int beforeId;
int afterId;
string type;
int delay;
};
{ Precedence } Precedences = ...;
//----------------------------------Capabilities
tuple Capability {
key int id;
string name;
};
{ Capability } Capabilities = ...;
//--------------------------------Workers
tuple WorkerDat {
key int id;
string name;
string type;
int cap;
};
{ WorkerDat } Workers = ...;
{string} WorkersTypes = {w.name | w in Workers};
//-------------------------------Proficiency
tuple Proficiency {
int workerId;
int capabilityId;
int level;
};
{ Proficiency } Proficiencies = ...;
//------------------------------Requirements
tuple Requirement {
key int id;
int taskId;
int fundedeffort;
};
{ Requirement } Requirements = ...;
//--------------------------------Required Capabilities
tuple RequiredCapability {
key int id;
int capabilityId;
int levelMin;
int levelMax;
int Funded;
};
{ RequiredCapability } RequiredCapabilities = ...;
//-----------------------------------Filter Expression
{ int } CandidateWorkers[r in Requirements] =
{ p.workerId| p in Proficiencies, n in RequiredCapabilities:
(n.id==r.id) &&
(p.capabilityId==n.capabilityId) &&
(n.levelMin <= p.level) &&
(p.level <= n.levelMax)
};
//--------------------------------Allocations
tuple Alloc {
int reqId;
int workerId;
string worker_name;
string worker_type;
string name;
int Fundeds;
int ptMin;
};
{ Alloc } Allocations = { <r.id, i,w.name, w.type, t.name, r.fundedeffort, t.ptMin> | r in Requirements, c in RequiredCapabilities, w in Workers, t in Tasks,i in CandidateWorkers[r] :
r.taskId==t.id && w.id ==i};
int Horizon =5760;
/**********************
* Decision variables *
**********************/
dvar interval task[t in Tasks] size t.Cont_Min.. t.Cont_Max;
dvar interval alts[a in Allocations] optional ; //possible allocation of worker to a task requirements
dvar interval worker[w in Workers] optional;
//---- Cumul Functions
cumulFunction cumuls[wc in Workers]=
sum(a in Allocations: a.workerId== wc.id ) pulse (alts[a],264);
/***************
* Constraints *
***************/
subject to {
//Project Portfoilos: each parent spans all its children
forall (t in Tasks : t.id in Parents)
span(task[t], all(i in ParentLinks: i.parentId == t.id) task[<i.taskId>]);
// Precedence constraints
// start of task "beforeId" ends at least "delay" hours before start of task "afterId"
forall (p in Precedences : p.type == "StartsAfterEnd")
endBeforeStart(task[<p.beforeId>], task[<p.afterId>], p.delay);
// start of task "beforeId" ends at least "delay" hours before start of task "afterId"
forall (p in Precedences : p.type == "StartsAfterStart")
startBeforeStart(task[<p.beforeId>], task[<p.afterId>], p.delay);
// start of task "beforeId" start at task "afterId"
forall (p in Precedences : p.type == "StartsAtStart")
startAtStart(task[<p.beforeId>], task[<p.afterId>], p.delay);
// Alternatives of workers who can fulfil task requirement (each requirement must be filled by one worker)
forall (r in Requirements)
alternative(task[<r.taskId>], all(a in Allocations: a.reqId==r.id) alts[a]);
// worker must span all alts variable for that workers
forall(w in Workers)
span(worker [w], all(a in Allocations: a.workerId==w.id) alts[a]) ;
forall( t in Tasks, r in Requirements)
sum(a in Allocations: t.id==r.taskId) sizeOf(alts[a], a.ptMin)== t.ptMin;
forall (wc in Workers) {
cumuls[wc] <= 480;
}
}
#CPOptimizer#DecisionOptimization