Assignment 1 Large Scale Optimisation Kavitha C Didugu
Assignment 1 Large Scale Optimisation Kavitha C Didugu
Assignment 1 Large Scale Optimisation Kavitha C Didugu
Kavitha C Didugu
Question 1:
#include<stdio.h>
#include<conio.h>
#include<iostream>
#include<fstream>
#include<iosfwd>
#include<string>
#include <deque>
#include <sstream>
#include <time.h>
//#include <iomanip.h>
#include <stdlib.h>
#include <vector>//for vectors
#include <math.h>
//#include <cplex.h>
#include <ilcplex/ilocplex.h>
//#include <iloconcert/ilomodel.h>
//#include <iloconcert/iloenv.h>
#include <ilconcert/ilosys.h>
ILOSTLBEGIN
Obj.end();
model.add( 8*X1 + 2*X2 + X3 + 4*X4 <= 10);
model.add(X1+X2<=1);
model.add(X3+X4<=1);
// Optimize
IloCplex cplex(model);
cplex.solve();//solving the MODEL
if (cplex.getStatus() == IloAlgorithm::Infeasible) // if the problem is infeasible
{
env.out() << "Problem Infeasible" << endl;
}
X1_val = cplex.getValue(X1);
X2_val = cplex.getValue(X2);
X3_val = cplex.getValue(X3);
X4_val = cplex.getValue(X4);
// Print results
cout<< "Objective Value = " << cplex.getObjValue() << endl;
cout<<"X1 = "<<X1_val<<endl;
cout<<"X2 = "<<X2_val<<endl;
cout<<"X3 = "<<X3_val<<endl;
cout<<"X4 = "<<X4_val<<endl;
}
catch(IloException &e)
{
env.out() << "ERROR: " << e << endl;
}
catch(...)
{
env.out() << "Unknown exception" << endl;
}
env.end();
return 0;
}
OUTPUT
Question 2:
#include<stdio.h>
#include<conio.h>
#include<iostream>
#include<fstream>
#include<iosfwd>
#include<string>
#include <deque>
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <ilcplex/ilocplex.h>
#include <ilconcert/ilosys.h>
ILOSTLBEGIN
IloBoolVarArray y(env,M);
IloBoolArray yv(env,M);
IloNumArray alliance_of_carrier(env, 8);//xij
//A2D x(env);
IloNumArray lane_demand(env,N); IloNumArray MQC(env,N);
IloNumArray alliance_bound(env,N); IloNumArray carrier_bound(env,N);
//TwoDMatrix xv(env);
TwoDMatrix price_data(env,N); //flow data between pairs of nodes*/
int aoc[30][8];
try
{
///////// DATA FILE READING //////////
const char* data_filename1 = "500_30_data_1_price.dat";
const char* data_filename2 = "500_30_data_1_demand.dat";
fstream fin1, fin2;
fin1.open(data_filename1,ios::in);
fin2.open(data_filename2,ios::in);
fin2 >> lane_demand >> MQC >> carrier_bound >> alliance_bound;
fin2 >> alliance_of_carrier;
fin1 >> price_data;
fin1.close();
fin2.close();
N = lane_demand.getSize();
cout<<"Number of lanes = "<<N<<endl;
M = MQC.getSize();
cout<< "Number of carriers="<<M<<endl;
ofstream fout;
fout.open("A3Q2 Volumes.txt");
// ----------data read------------------------------------------------
IloModel model(env);
//=======================================================================
for (int i=0;i<N;i++)
{
x[i]=IloNumVarArray(env, N, 0, IloInfinity,ILOFLOAT);
x_val[i]=IloNumArray(env, N);
for(int j=0;j<N;j++)
{
IloExpr SumZ(env);
for(int i=0;i<M;i++)
{
SumZ+=x[i][j];
}
model.add(SumZ>=lane_demand[j]);
SumZ.end();
}
SumP+=price_data[t][j]*x[t][j];
}
model.add(SumP<=(1+alpha)*price_data[i][j]*lane_demand[j]+(1-
y[i])*D);
SumP.end();
}
SumA+=x[i][j]*aoc[i][k];
}
model.add(SumA<=alliance_bound[j]*lane_demand[j]);
SumA.end();
}
//Optimize
IloCplex cplex(model);
// Print results
env.end();