0
votes

i'm a newbie using CPLEX Studio IDE 12.8.0 (built on eclipse), i'm trying to write my 1st model. i watched youtube videos and started coding an assignment workforce problem according to their tasks proficiency into 5 teams, i have 3 questions :

1-how to get rid of the errors,in the declaration of the objective function

// parameters 
int n=...; //number of operators  
int m=...; //number of tasks
int w=...; //number of teams  

range operateurs= 1..n; //intervalle des opérateurs 
range taches = 1..m;   // varier les taches 
range equipes = 1..w; //  varier les équipes 

int notation[operateurs][taches]; 
dvar boolean affectation[operateurs][taches][equipes];  

**Maximize Sum (i in operateurs, j in taches, k in equipes) affectation[i][j][k]*notation[i][j];**  
subject to {
forall (i in operateurs,j in taches)

unicite_aff_eq:  
sum (k in equipes) affectation[i][j][k]== 1;

forall (k in equipes,i in operateurs)
 unicite_aff_tache:

  sum (j in taches)affectation[i][j][k]== 1;

forall (k in equipes,j in taches) 

contenir_opp: 

sum (i in operateurs)   affectation[i][j][k]>= 1; 
forall (i in operateurs,j in taches,k in equipes)


competence:   
sum (i in operateurs,j in taches)
affectation[i][j][k]*notation[i][j]>=6; 
}

2- can you give me a hand with modeling this constraint:

//constraint that i did not know to modele it 
if (affectation[i][j][k]==1)

//at least there is   notation[i][j]>=3;

here's the .dat file

n=56; 

m=6; 

w=5; 

SheetConnection my_sheet ("affectation.xlsx");  

notation from sheetread(my_sheet,"notation"); 

3-how can i make the declaration to import the notation table from excel.

i will be grateful if you can help me guys thanks in advance

her's the error message that i get on the objective function declaration line (Maximize Sum (i in operateurs, j in taches, k in equipes) affectation[i][j][k]*notation[i][j];** ) //Description Ressource Chemin d'accès Emplacement Type syntax error, unexpected (identifier), expecting ';' affectation-Opérateur.mod /affectation-Opérateur 20:59-67 C:/Users/ToualbiaMohamed Lies/opl/affectation-Opérateur/affectation-Opérateur.mod Problème de structure du modèle OPL// with notation underlined in red. so i wonder what i did wrong and if it's possible tu multiply a matrix by a cube (should make a declaration about the number of teams in the .dat file)

1

1 Answers

0
votes

for 1) and 2) the following code works

// parameters 
int n=2; //number of operators  
int m=4; //number of tasks
int w=5; //number of teams  

range operateurs= 1..n; //intervalle des opérateurs 
range taches = 1..m;   // varier les taches 
range equipes = 1..w; //  varier les équipes 

int notation[o in operateurs][t in taches]=o*t mod 2; 
dvar boolean affectation[operateurs][taches][equipes];  

maximize sum (i in operateurs, j in taches, k in equipes) affectation[i][j][k]*notation[i][j];  
subject to {
forall (i in operateurs,j in taches)

unicite_aff_eq:  
sum (k in equipes) affectation[i][j][k]== 1;

forall (k in equipes,i in operateurs)
 unicite_aff_tache:

  sum (j in taches)affectation[i][j][k]== 1;

forall (k in equipes,j in taches) 

contenir_opp: 

sum (i in operateurs)   affectation[i][j][k]>= 1; 
forall (i in operateurs,j in taches,k in equipes)


competence:   
sum (i in operateurs,j in taches)
affectation[i][j][k]*notation[i][j]>=6; 

forall (i in operateurs,j in taches,k in equipes)
(affectation[i][j][k]==1)=> (notation[i][j]>=3);


}

for 3) in Making Decision optimization simple you could have a look at Excel spreadsheets

.mod

tuple param
{
int nbKids;
}

{param} params=...;

assert card(params)==1;

int nbKids=first(params).nbKids;

// a tuple is like a struct in C, a class in C++ or a record in Pascal
tuple bus
{
key int nbSeats;
float cost;
}

// This is a tuple set
{bus} buses=...;

// asserts help make sure data is fine
assert forall(b in buses) b.nbSeats>0;
assert forall(b in buses) b.cost>0;

// decision variable array
dvar int+ nbBus[buses];

// objective
minimize
 sum(b in buses) b.cost*nbBus[b];

// constraints
subject to
{
 sum(b in buses) b.nbSeats*nbBus[b]>=nbKids;
}

tuple result
{
   key int nbSeats;
   int nbBuses;
}

{result} results={<b.nbSeats,nbBus[b]> | b in buses};

.dat

SheetConnection s("zoo.xlsx");

params from SheetRead(s,"params!A2");
buses from SheetRead(s,"buses!A2:B3");

results to SheetWrite(s,"buses!E2:F3");