Originally posted by: thomasmoreaumaster
Hi everybody,
My name is Thomas and i'm a master degree student in France.
I started one month ago a new project , But i'm stucked and i can't find any solutions this is why i'm posting a new topic.
First of all, all i needed to do is implement thoses methods bellow:
4.1 Linearization
We use the formulation (2)-(5) to develop a mixed integer linear programming (MILP)
formulation for MRCP. We follow the linearization framework proposed by Wu (1997).
4.2 Binary search
Binary search has been used as a method to solve fractional programming problems
by Lawler (1976) and Ibaraki (1983). We adopt this method for MRCP as follows.
4.3 Newton's method
Newton's MNewton's Method for fractional programming problems was proposed by Isbell and
Marlow (1956) and has been adapted to MRCP here.ethod for fractional programming problems was proposed by Isbell and
But all i can get from my computer is an error of type : terminate called after throwing an instance of 'IloCplex::Exception'
Or terminate called after throwing an instance of 'IloAlgorithm::CannotExtractException'
I did spend a lotf of times on the internet in order to find what is wrong with my code but i couldn't find.
Here is my code in CPP using Concert Technology:
#include"Compute.h"
using namespace std;
ILOSTLBEGIN//
void q_compute(int size,std::vector<double> vector_a_i,std::vector<double> vector_b_i,double alpha,std::vector<std::vector<int> > &matr,std::vector<int> clique,double & palpha,std::vector<int> & c_alpha)
{
//Creating environment
IloEnv env;
//creating the model
IloModel model(env);
//creating variable x
IloNumVarArray x(env,size,0,1,ILOBOOL);
cout<<"creating objective function"<<endl;
IloExpr obj(env);
for(int i=0;i<size;++i)
{
obj+=vector_a_i[i]*x[i];
obj-=vector_b_i[i]*alpha*x[i];
}
IloObjective obj2 (env,obj,IloObjective::Maximize);
model.add(obj2);
// model.add(IloMaximize(env,obj));
cout<<"creating constraints"<<endl;
for(int i=0;i<size;++i)
for(int j=0;j<size;++j)
if(i!=j && !matr[i][j])
model.add(x[i]+x[j]<=1);
cout<<"First added"<<endl;
for(int j=0;j<size;++j)
{
IloExpr cont(env);
for(int i=0;i<size;++i)
cont+=(1-matr[i][j])*x[i];
model.add(cont>=1);
}
for(int i=0;i<size;++i)
{
model.add(x[i]<=1);
model.add(x[i]>=0);
}
cout<<"model"<<endl;
IloCplex cplex(model);
cout<<"Solving the problem"<<endl;
cplex.solve();
cout<<"cplex solved"<<endl;
//Print results
cout << "The objective value is " << cplex.getObjValue() << endl;
palpha=cplex.getObjValue();
for(int i=0;i<size;++i)
{
cout << "X :"<<i<<" values are " << cplex.getValue(x[i]) << endl;
c_alpha[i]=cplex.getValue(x[i]);
}
env.end();
}
double getAlpha1(std::vector<int> anyMC,std::vector<double> vector_a_i,std::vector<double> vector_b_i)
{
double a=0,b=0;
for(int i=0;i<anyMC.size();++i)
{
if(anyMC[i])
{
a+=vector_a_i[i];
b+=vector_b_i[i];
}
}
return a/b;
}
void m_compute(int size,std::vector<double> vector_a_i,std::vector<double> vector_b_i,std::vector<std::vector<int> > &matr,std::vector<int> clique,double LowerBound,double UpperBound)
{
//creating environment
IloEnv env;
//creating model
IloModel model(env);
//creating variable x
IloNumVarArray x(env,size,0,1,ILOINT);
cout<<"creating objective function"<<endl;
IloExpr cont(env);
for(int i=0;i<size;++i)
cont+=(1/(vector_b_i[i]*x[i]));
IloExpr obj(env);
for(int i=0;i<size;++i)
obj+=vector_a_i[i]*cont*x[i];
model.add(IloMaximize(env,obj));
cout<<"creating constraints"<<endl;
for(int i=0;i<size;++i)
for(int j=0;j<size;++j)
if(i!=j && !matr[i][j])
model.add(x[i]+x[j]<=1);
cout<<"First added mcompute"<<endl;
for(int j=0;j<size;++j)
{
IloExpr cont2(env);
for(int i=0;i<size;++i)
cont2+=(1-matr[i][j])*x[i];
model.add(cont2>=1);
}
cout<<"Second Added"<<endl;
IloExpr cont3(env);
for(int i=0;i<size;++i)
cont3+=vector_b_i[i]*cont*x[i];
model.add(cont3==1);
cout<<"Third added"<<endl;
for(int i=0;i<size;++i)
if(clique[i])
{
model.add(cont*x[i]<=UpperBound*x[i]);
model.add(cont*x[i]>=LowerBound*x[i]);
model.add(cont*x[i]<=cont-LowerBound*(1-x[i]));
model.add(cont*x[i]>=cont-UpperBound*(1-x[i]));
model.add(cont >= LowerBound);
model.add(cont <= UpperBound);
model.add(cont*x[i]>=0);
}
cout<<"Creating model"<<endl;
IloCplex cplex(model);
cout<<"Solving the problem"<<endl;
cplex.solve();
//Print results
cout << "The objective value is " << cplex.getObjValue() << endl;
for(int i=0;i<x.getSize();++i)
cout << "X :"<<i<<" values are " << cplex.getValue(x[i]) << endl;
env.end();
}
You'll find in attachments the file that i used to buil my code from.
Can someon can see what is wrong ?
Thank you very much for your time and your answer,
Thomas.
#CPLEXOptimizers#DecisionOptimization