Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string>
  3. #include <ilcplex/ilocplex.h>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main() {
  9.     IloEnv env;
  10.     IloModel inksProblem(env, "Inks Problem");
  11.     IloCplex cplex(inksProblem);
  12.  
  13.     IloIntVarArray SR(env, 4, 0, IloInfinity); // SolA SolB SEC COR
  14.     IloIntVarArray SN(env, 4, 0, IloInfinity); // SolA SolB SEC COR
  15.     double price[] = {1.5, 1, 4, 6};
  16.     string names[] = {"SolA", "SolB", "SEC", "COR"};
  17.     //restrictions
  18.     IloExpr litersSumSR(env);
  19.     IloExpr litersProportionSRsec(env);
  20.     IloExpr litersProportionSRcor(env);
  21.     IloExpr litersSumSN(env);
  22.     IloExpr litersProportionSNsec(env);
  23.     IloExpr litersProportionSNcor(env);
  24.     for(int i = 0; i < 4; ++i){
  25.         litersSumSR+=SR[i];
  26.         litersSumSN+=SN[i];
  27.     }
  28.     inksProblem.add(litersSumSR == 1000);
  29.     inksProblem.add(litersSumSN == 250);
  30.  
  31.     litersProportionSRsec = (SR[0]*0.3 + SR[1]*0.6 + SR[2])/1000;
  32.     litersProportionSRcor = (SR[0]*0.7 + SR[1]*0.4 + SR[3])/1000;
  33.  
  34.     inksProblem.add(litersProportionSRsec >= 0.25);
  35.     inksProblem.add(litersProportionSRcor >= 0.5);
  36.  
  37.     litersProportionSNsec = (SN[0]*0.3 + SN[1]*0.6 + SN[2])/250;
  38.     litersProportionSNcor = (SN[0]*0.7 + SN[1]*0.4 + SN[3])/250;
  39.  
  40.     inksProblem.add(litersProportionSNsec >=0.2);
  41.     inksProblem.add(litersProportionSNcor >= 0.5);
  42.  
  43.     //objective function
  44.  
  45.     IloExpr waste(env);
  46.     for(int i = 0; i < 4; ++i){
  47.         waste += SR[i] * price[i];
  48.         waste += SN[i] * price[i];
  49.     }
  50.  
  51.     inksProblem.add(IloMinimize(env, waste));
  52.  
  53.     cplex.solve();
  54.     printf("Minimum Waste = %lf R$\n", cplex.getObjValue());
  55.     env.end();
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement