0% found this document useful (0 votes)
51 views

Combining Different Modes of Transport

This C++ program defines data types for arrays of decision variables and reads in transportation problem data from a file. It then builds a transportation model using CPLEX, minimizing the total transportation and changeover costs. It solves the model and outputs the objective value and values of the decision variables.

Uploaded by

jabir pv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Combining Different Modes of Transport

This C++ program defines data types for arrays of decision variables and reads in transportation problem data from a file. It then builds a transportation model using CPLEX, minimizing the total transportation and changeover costs. It solves the model and outputs the objective value and values of the decision variables.

Uploaded by

jabir pv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<ilcplex/ilocplex.h> //10.

5
ILOSTLBEGIN
typedef IloArray<IloNumVarArray> IloNumVarArray2;
typedef IloArray<IloBoolVarArray> IloBoolVarArray2;
typedef IloArray<IloBoolVarArray> IloBoolVarArray3;
int main()
{
IloEnv env;
try
{
const char* filename="E:\Lab Softwares\Data Analysis Lab\Cplex data files\transport.dat";
ifstream file(filename);
IloNumVarArray leg(env),mode(env);
IloNumVarArray2 ctran(env),cchange(env);
file>>leg>>mode>>ctran>>cchange;
IloModel mod(env);
IloInt t=leg.getSize();
IloInt p,q,r;
IloBoolVarArray2 use(env),change(env);
for(p=0;p<t<p++)
{
use.add(IloBoolVarArray(env,t));
for(q=0;q<t;q++)
change.add(IloBoolVarArray(env,t));
}
IloExpr TT(env),TC(env);
for(p=0;p<t;p++)
{
for(q=0;q<t;q++)
{
TT+=ctran[p][q]*use[p][q];
for(r=0;r<t;r++)
TC+=cchange[p][q]*change[p][q][r];
}
}
mod.add(IloMinimize(env,TT+TC));
TT.end();
TC.end();
IloExpr tuse(env),tchange(env);
for(p=0;p<t;p++)
{
for(q=0;q<t;q++)
{
tuse+=use[q][p];
}
mod.add(tuse==1);
}
tuse.end();
for(p=0;p<t;p++)
{
for(q=0;q<t;q++)
for(r=0;r<t;r++)
tchange+=change[p][q][r];
mod.add(tchange==1);
}
tchange.end();
for(p=0;p<t;p++)
{
for(q=0;q<t;q++)
for(r=0;r<t;r++)
mod.add((use[p][r]+use[q][r+1])>=2*change[p][q][r]);
}

IloCplex cplex(mod);
cplex.exportModel("E:\Lab Softwares\Data Analysis Lab\Cplex data files\10_5.lp");
cplex.solve();
env.out()<<endl<<"Total cost = "<<cplex.getObjValue()<<endl;
for(p=0;p<t;p++)
{
for(q=0;q<t;q++)
{
env.out()<<'\t'<<cplex.getValue(use[p][q]);
}
env.out()<<'\n';
}
env.out()<<"[";
for(p=0;p<t;p++)
{
env.out()<<"[";
for(q=0;q<t;q++)
{
env.out()<<"[";
for(r=0;r<t;r++)
env.out()<<'\t'<<cplex.getValue(change[p][q][r]);
env.out()<<"]";
}
env.out()<<"]";
}
env.out()<<"]";
}
catch(IloException& e)
{
cerr<<"Error = "<<e<<endl;
}
catch(...)
{
cerr<<"Unknown error occured"<<endl;
}
env.end();
return 0;
}

You might also like