0

I need to optimize a selection of investments that have the highest total impact. The constraints are that the total Investments can be maximum of 8.0 An additional constrain is that each Category can only be assessed twice

The problem I face is that the constraint for max Investment does not work. Also I can not find how to implement the Category constraint. Links to related forms are also welcome.

My code is attached below

Many thanks

--

int NumberofProjects = 12;
range Project = 1..NumberofProjects; // 12 different projects

//Declaration of Parameters
float Impact[Project] = [0.1, 0.03, 0.07, 0.13, 0.01, 0.04, 0.07, 0.08, 0.15, 0.12, 0.02, 0.04]; // Impact to maximize 
float Investment[Project] = [2.0, 1.6, 2.5, 12.0, 10.3, 0.6, 1.2, 1.9, 4.0, 5.0, 0.2, 0.5]; // costs --> can be max 8.0 
string Category[Project] = [1,1,1,1,1,2,2,2,3,3,3,3] 
float Budget = 8.0;
// Declaration of Parameters 

//Expression of Decision 
dexpr float Reduction = sum(p in Project) Impact[p];

//Objective Function
maximize Reduction;

//Constraints
constraint ctCapResources[Project];
subject to {
forall (p in Project)
    ctCapResources[p]: sum(p in Project)
        Investment[p] <= Budget;
}
BST
  • 11
  • 1

2 Answers2

0

the main issue is that you forgot to add decision variables.

int NumberofProjects = 12;
range Project = 1..NumberofProjects; // 12 different projects

//Declaration of Parameters
float Impact[Project] = [0.1, 0.03, 0.07, 0.13, 0.01, 0.04, 0.07, 0.08, 0.15, 0.12, 0.02, 0.04]; // Impact to maximize 
float Investment[Project] = [2.0, 1.6, 2.5, 12.0, 10.3, 0.6, 1.2, 1.9, 4.0, 5.0, 0.2, 0.5]; // costs --> can be max 8.0 
int Category[Project] = [1,1,1,1,1,2,2,2,3,3,3,3];
float Budget = 8.0;
// Declaration of Parameters 

// decision variable
dvar boolean invest[Project];

//Expression of Decision 
dexpr float Reduction = sum(p in Project) Impact[p]*invest[p];

//Objective Function
maximize Reduction;

//Constraints
constraint ctCapResources[Project];
subject to {
forall (p in Project)
    ctCapResources[p]: sum(p in Project)
        Investment[p]*invest[p] <= Budget;
        
 //  each Category can only be assessed twice
 
 forall(c in 1..3) sum(p in Project:Category[p]==c) invest[p]<=2;
}

will work much better

And for your second question you could change

maximize Reduction;

into

maximize staticLex(Reduction,-Cost);
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
0

@alexfleischer - Thank you very much Alex. Much appreciated. I have one follow-up question. I have included an index for two methods of manufacturing (ie Internal and External) and would like to add the following restriction: • At most one of the following three projects can be done internally: project 1, project 4, project 5. Also, I noticed that, while the optimal outcome achieved (highest Impact), it does not think about costs (there are two answers yielding same Impact but different Costs), while I would like to incorporate as secondary (less important) objective (should be possible with CPLEX 12.9?)

int NumberofProduction = 2;
range Production = 1..NumberofProduction; // Internal vs External production

int NumberofProjects = 12;
range Project = 1..NumberofProjects; // 12 different projects

//Declaration of Parameters
float Impact[Project] = [0.1, 0.03, 0.07, 0.13, 0.01, 0.04, 0.07, 0.08, 0.15, 0.12, 0.02, 0.04]; // Impact to maximize 
//float Investment[Project] = [2.3, 1.7, 2.9, 2.3, 0.4, 0.7, 1.4, 2.2, 4.5, 5.5, 0.3, 0.6]; // costs --> can be max 8.0 
// float Setupcosts[Project] = [0.3, 0.1, 0.4, 0.3, 0.1, 0.1, 0.2, 0.3, 0.5, 0.5, 0.1, 0.1];
// float ExInvestment[Project] = [2.5, 1.7, 2.0, 2.5, 0.4, 0.7, 1.8, 2.2, 4.5, 1.0, 0.4, 0.5];
float InExInvestment[Production][Project] = [[2.3, 1.7, 2.9, 2.3, 0.4, 0.7, 1.4, 2.2, 4.5, 5.5, 0.3, 0.6],[2.5, 1.7, 2.0, 2.5, 0.4, 0.7, 1.8, 2.2, 4.5, 1.0, 0.4, 0.5]];
int Category[Project] = [1,1,1,1,1,2,2,2,3,3,3,3];
float Budget = 8.0;

// decision variable
dvar boolean invest[Production][Project];

//Expression of Decision 
dexpr float Reduction = sum(q in Production, p in Project) Impact[p]*invest[q][p];
// dexpr float Costs = sum(q in Production, p in Project) -1*InExInvestment[q][p]; // Second decision to mimimize costs if two options for Reduction with same outcome
//Constraints
constraint ctCapResources[Project];
constraint ctProject[Project];


//Objective Function
maximize Reduction;


subject to {

 //  each Category can only be assessed twice
 forall (p in Project)
        ctProject[p]: sum(q in Production)invest[q][p] <=1;
 
 forall(c in 1..3) sum(p in Project:Category[p]==c, q in Production) invest[q][p]<=2;
 
 forall (p in Project)
    ctCapResources[p]: sum(q in Production, p in Project)
        InExInvestment[q][p]*invest[q][p] <= Budget;
}
BST
  • 11
  • 1