summaryrefslogtreecommitdiff
path: root/code/linprog
diff options
context:
space:
mode:
authorRemyaDebasis2018-07-23 20:01:22 +0530
committerRemyaDebasis2018-07-23 20:01:22 +0530
commit69460c03b8b53068d60fd08d3180efc91e627603 (patch)
tree1689256f9ca4b9ce8076d3da8d5dac1b76963859 /code/linprog
parentf2539f26af7794da4ea4ccd8ae5ec2c753e94212 (diff)
downloadFOT_Examples-69460c03b8b53068d60fd08d3180efc91e627603.tar.gz
FOT_Examples-69460c03b8b53068d60fd08d3180efc91e627603.tar.bz2
FOT_Examples-69460c03b8b53068d60fd08d3180efc91e627603.zip
added code files
Diffstat (limited to 'code/linprog')
-rw-r--r--code/linprog/Blending_problem.sce135
-rw-r--r--code/linprog/Employee Scheduling.sce83
-rw-r--r--code/linprog/FuelOil.sce86
-rw-r--r--code/linprog/Reddy_Mikks.sce84
-rw-r--r--code/linprog/TOOLCO.sce82
-rw-r--r--code/linprog/TOYCO Dual.sce88
-rw-r--r--code/linprog/TOYCO model.sce67
7 files changed, 625 insertions, 0 deletions
diff --git a/code/linprog/Blending_problem.sce b/code/linprog/Blending_problem.sce
new file mode 100644
index 0000000..24b80ad
--- /dev/null
+++ b/code/linprog/Blending_problem.sce
@@ -0,0 +1,135 @@
+// A practcal problem of blending of different products to acheive designed performance levels.
+// This is an example from the class of allocation problems.
+// Ref:H.A. Eiselt and C.-L.SAndblom,"Linear Programming and its Applications",Springer-Verlag Berlin Heidelberg 2007,chapter 2.7
+//Example:
+//A firm faces the problem of blending three raw materials into two final
+//products. The required numerical information is provided in Table.
+//
+//-----------------------------------------------------------------------
+// Raw Products Amount available Unit Cost
+//Materials 1 2 (in tons) ($)
+//-----------------------------------------------------------------------
+// 1 [0.4;0.6][0.5;0.6] 2000 1
+// 2 [0.1;0.2][0.1;0.4] 1000 1.5
+// 3 [0.2;0.5][0.2;0.3] 500 3
+//-----------------------------------------------------------------------
+//quantity required 600 700
+//(in tons)
+//-----------------------------------------------------------------------
+//unit selling price 10 8
+//($)
+//-----------------------------------------------------------------------
+//we assume that raw materials blend linearly, meaning that taking,
+//say, α units of raw material A and β units of raw material B, then
+//the resulting blend C has features that are proportional to the
+//quantities of A and B that C is made of. As an example, take 3 gallons
+//of 80º water and 2 gallons of 100º water,then the result would be 5
+//gallons of water, whose temperature is [3(80) + 2(100)]/5 = 88º.
+//The parameters max and min indicate the smallest and largest proportion
+//of rawmaterial that is allowed in the final product.Determine the
+//optimal transportation plan to maximize profit.
+
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:Debasis Maharana
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//======================================================================
+clc;
+Nprod = 2;
+Nraw = 3;
+demand = [600 700];
+cost = [10 8];
+con(1,:,:) = [0.4 0.6;0.1 0.2;0.2 0.5];
+con(2,:,:) = [0.5 0.6;0.1 0.4;;0.2 0.3];
+raw = [2000 1000 500];
+RawC = [1 1.5 3];
+mprintf('Received Data')
+mprintf('Number of products %d',Nprod);
+mprintf('number of raw materials %d',Nraw);
+disp(demand,'Demand of products');
+disp(cost,'Unit cost of products');
+
+product = [];Min_Max = [];
+for i = 1:Nprod
+ product = [product,['Min-Max',string(i)]];
+ for j = 1:Nraw
+ MM(j,:) = con(i,j,:);
+ end
+ Min_Max = [Min_Max string(MM)];
+end
+Row1 = ['Raw Material',product,'Amount_avail','unit_Cost']
+RawMaterial = string([1:Nraw]');
+Amount_avail = string(raw(:));
+unit_C = string(RawC(:));
+Table = [Row1;[RawMaterial Min_Max Amount_avail unit_C]];
+disp(Table);
+input('Press Enter to proceed ')
+A1 = zeros(Nraw,Nraw*Nprod);
+for i = 1:Nraw
+ A1(i,i:Nraw:Nraw*Nprod)=1;
+ b1(i) = raw(i);
+end
+A2 = zeros(Nprod*Nraw*2,Nprod*Nraw);b2 = zeros(Nprod*Nraw*2,1);
+A3 = zeros(Nprod,Nprod*Nraw);
+for i = 1:Nprod
+ Areq = ones(2*Nraw,Nraw);
+ Areq(Nraw+1:2*Nraw,:) = -1;
+ for j =1:Nraw
+ Areq(j,:) = con(i,j,1)* Areq(j,:);
+ Areq(j,j) = Areq(j,j)-1;
+ Areq(Nraw+j,:) = Areq(Nraw+j,:)*con(i,j,2);
+ Areq(Nraw+j,j) = 1 + Areq(Nraw+j,j);
+ end
+ A2((i-1)*2*Nraw+1:i*2*Nraw,(i-1)*Nraw+1:i*Nraw) = Areq;
+ A3(i,(i-1)*Nraw+1:i*Nraw)= ones(1,Nraw);
+ b3(i) = demand(i);
+end
+
+A = [A1;A2];b = [b1;b2];
+Aeq = A3;beq = b3;
+C = [];
+for i = 1:Nprod
+ C1 = -cost(i)*ones(1,Nraw) + RawC;
+ C = [C ;C1'];
+end
+
+lb = zeros(1,Nprod*Nraw);
+intcon = 1:Nprod*Nraw;
+[xopt,fopt,exitflag,output,lambda] = linprog(C,A,b,Aeq,beq,lb,[]);
+clc
+select exitflag
+case 0 then
+ mprintf('Optimal Solution Found')
+ input('Press enter to view results')
+ //Display results
+ mprintf('Total profit is %d\n',-fopt);
+
+ A1 = [];product = [];
+ for i=1:Nprod
+ Raw_M(:,i) = xopt((i-1)*Nraw+1:i*Nraw) ;
+ product(i) = string(sum(Raw_M(:,i)));
+ A1 = [A1 strcat(['Product' string(i)])];
+ end
+
+ table = [['RawMaterial', A1];[RawMaterial string(Raw_M)];['Total Product' product']];
+ disp(table);
+case 1 then
+ mprintf('Primal Infeasible')
+case 2 then
+ mprintf('Dual Infeasible')
+case 3
+ mprintf('Maximum Number of Iterations Exceeded. Output may not be optimal')
+case 4
+ mprintf('Solution Abandoned')
+case 5
+ mprintf('Primal objective limit reached')
+else
+ mprintf('Dual objective limit reached')
+end
+
+
diff --git a/code/linprog/Employee Scheduling.sce b/code/linprog/Employee Scheduling.sce
new file mode 100644
index 0000000..5fdce02
--- /dev/null
+++ b/code/linprog/Employee Scheduling.sce
@@ -0,0 +1,83 @@
+//Employee Scheduling
+//Macrosoft has a 24-hour-a-day, 7-days-a-week toll free hotline that is being set up to answer questions regarding a new product. The following table summarizes the number of full-time equivalent employees (FTEs) that mustbe on duty in each time block.
+//
+//Interval Time FTEs
+// 1 0-4 15
+// 2 4-8 10
+// 3 8-12 40
+// 4 12-16 70
+// 5 16-20 40
+// 6 20-0 35
+//Macrosoft may hire both full-time and part-time employees. The former work 8-hour shifts and the latter work 4-hour shifts; their respective hourly wages are $15.20 and $12.95. Employees may start work only at the beginning of 1 of the 6 intervals.Part-time employees can only answer 5 calls in the time a full-time employee can answer 6 calls. (i.e., a part-time employee is only 5/6 of a full-time employee.) At least two-thirds of theemployees working at any one time must be full-time employees.Formulate an LP to determine how to staff the hotline at minimum cost.
+
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:Debasis Maharana
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//======================================================================
+
+clc;
+
+Interval = 1:6;
+Time = 0:4:20;
+FTEs = [15 10 40 70 40 35];
+intr = [];
+Ninterval = length(Interval);
+for i = 1:Ninterval-1
+ intr = [intr;strcat([string(Time(i)),'-',string(Time(i+1))])];
+end
+
+intr = [intr;strcat([string(Time(i)),'-',string(Time(1))])];
+
+table = [['Interval','Time','Full-time Emp Req'];[string(Interval'),intr,string(FTEs')]];
+mprintf('Data received');
+disp(table);
+input('press enter to proceed');
+
+A1 = zeros(Ninterval,2*Ninterval);b1 = zeros(Ninterval,1);
+A2 = zeros(Ninterval,2*Ninterval);b2 = zeros(Ninterval,1);
+A1(1,[1 Ninterval Ninterval+1]) = [-1 -1 -5/6]; b1(1) = -15;
+A2(1,[1 Ninterval Ninterval+1]) = [-1/3 -1/3 2/3];
+for i = 2:Ninterval
+ A1(i,i-1:i) = -1;
+ A1(i,Ninterval+i) = -5/6;
+ b1(i) = -FTEs(i);
+
+ A2(i,i-1:i)=-1/3;
+ A2(+i,Ninterval+i)=2/3;
+end
+A= [A1;A2];b = [b1;b2];
+Cost = [15.20*8*ones(1,Ninterval) 12.95*4*ones(1,Ninterval)]';
+lb = zeros(1,2*Ninterval);ub = [];
+[xopt,fopt,exitflag,output,lambda] = linprog(Cost,A,b,[],[],lb,ub)
+
+clc
+select exitflag
+case 0 then
+ mprintf('Optimal Solution Found')
+ input('Press enter to view results')
+ //Display results
+ mprintf('Total Cost is %d\n',-fopt);
+ table(:,4:5) = [['Full time Emp', 'Part-Time Emp'];[string(xopt(1:6)) string(xopt(7:12))]];
+ disp(table);
+case 1 then
+ mprintf('Primal Infeasible')
+case 2 then
+ mprintf('Dual Infeasible')
+case 3
+ mprintf('Maximum Number of Iterations Exceeded. Output may not be optimal')
+case 4
+ mprintf('Solution Abandoned')
+case 5
+ mprintf('Primal objective limit reached')
+else
+ mprintf('Dual objective limit reached')
+end
+
+
+
diff --git a/code/linprog/FuelOil.sce b/code/linprog/FuelOil.sce
new file mode 100644
index 0000000..305cd7a
--- /dev/null
+++ b/code/linprog/FuelOil.sce
@@ -0,0 +1,86 @@
+// This example shows the use of equality constraint and corrosponding unrestricted dual variables
+//Example:
+//A refinery produces, on average, 1000 gallon/hour of virgin pitch in its crude distillation operation. This pitch may be blended with flux stock to make commercial fuel oil, or it can be sent in whole or in part to a visbreaker unit. The visbreaker produces an 80 percent yield of tar that can also be blended with flux stock to make commercial fuel oil. The visbreaking operation is economically break-even if the pitch and the tar are given no value, that is, the value of the overhead product equals the cost of the operation. The commercial fuel oil brings a realization of 5$/gal, but the flux stock has a cracking value of 8$/gal. This information together with the viscosity and gravity blending numbers and product specifications, appears in the following table. It is desired to operate for maximum profit.
+//
+//--------------------------------------------------------------------
+// Quantity available Value Viscosity Gravity
+// (gal/h) ($/gal) Bl.No. Bl. No
+//Pitch P = 1000-V 0 5 8
+//Visbreaker feed V 0 - -
+//Tar T = 0.8V 0 11 7
+//Flux F = any 8 37 24
+//Fuel oil P + T + F 5 21 min 12 min
+//---------------------------------------------------------------------
+//Suggest a operating condition for maximizing profit.
+
+// The primal model for this example is given as
+//Maximize 5*(P + T + F) - 8*F
+//subject to
+// 5*P + 11*T + 37*F >= 21*(P + T + F)
+// 8*P + 7*T + 24*F >= 12*(P + T + F)
+// P - T/0.8 = 0
+
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:Debasis Maharana
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//=================================================================================
+
+clc;
+//The problem can be execuated using slack variable too.
+//Users are encouraged to explore the use of slack variables.
+
+//Variables = [P T F]; Output = Fuel
+Viscosity = [5 11 37 21];
+Gravity = [8 7 24 12];
+Value = [8 5];
+
+A = [16 10 -16;4 5 -12];
+b = [0 0]';
+Aeq = [0.8 1 0];
+beq = 800;
+lb = [0 0 0];
+ub = [];
+C = -[5 5 -3]';
+Ncons = 3;Nvar = 3;
+//Dual problem
+Adual = -[A;Aeq]';
+bdual = C;
+C = [b;beq];
+// The varable corrosponding to equality constraint is unrestricted
+lb = [0 0 -%inf];
+ub = [];
+[xopt,fopt,exitflag,output,lambda] = linprog(C,Adual,bdual,[],[],lb,ub);
+clc
+
+select exitflag
+ //Display result
+case 0 then
+ mprintf('Optimal Solution Found');
+ input('Press enter to view results');clc;
+ mprintf('Revenue Generated %d\n',fopt);
+ disp(xopt(1:Ncons)','Dual values of the primal constraints');
+
+ for i = 1:Ncons
+ mprintf('\n A cost decrease of %f will occur in the current objective cost value per unit decrease in resource %d ',xopt(i),i)
+ end
+
+case 1 then
+ mprintf('Primal Infeasible')
+case 2 then
+ mprintf('Dual Infeasible')
+case 3
+ mprintf('Maximum Number of Iterations Exceeded. Output may not be optimal')
+case 4
+ mprintf('Solution Abandoned')
+case 5
+ mprintf('Primal objective limit reached')
+else
+ mprintf('Dual objective limit reached')
+end
+
diff --git a/code/linprog/Reddy_Mikks.sce b/code/linprog/Reddy_Mikks.sce
new file mode 100644
index 0000000..805c4e3
--- /dev/null
+++ b/code/linprog/Reddy_Mikks.sce
@@ -0,0 +1,84 @@
+// This is an infeasible problem example. The original problem has been modified by including demand.
+//Ref:H.A. TAHA,"OPERATIONS RESEARCH AN INTRODUCTION",PEARSON-Prentice Hall New Jersey 2007,chapter 2.1
+//Reddy Mikks produces both interior and exterior paints from two raw materials, M1 and M2. The following table provides the basic data of the problem
+//
+// tons of raw material per tons of
+// --------------------------------
+//Raw material Exterior paint Interior paint Maximum daily vailability (tons)
+//-------------------------------------------------------------------------------------------------
+//M1 6 4 24
+//M2 1 2 6
+//-------------------------------------------------------------------------------------------------
+//Profit per ton 5000 4000
+//-------------------------------------------------------------------------------------------------
+//A market survey indicates that the daily demand for interior paint cannot exceed that for exterior paint by more than 1 ton.
+// Also, There should be minimum production of 6 tons combining both paints(this part is changed from the main problem). Reddy Mikks wants to determine the optimum product mix of interior and exterior paints that maximizes the total daily profit.
+
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:Debasis Maharana
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//======================================================================
+
+clc;
+
+Nproducts = 2;
+Nrawmaterial = 2;
+profit_product =[5000 4000];
+product_Mix = [6 1;4 2];
+Raw_avail = [24 6];
+mprintf('Data received')
+mprintf('Number of product %d',Nproducts);
+mprintf('Number of Raw materials %d',Nrawmaterial);
+FirstR = ['Product 1','Product 2','available'];
+Raw_mat = ['M1','M2'];
+table = [['Raw material' FirstR];[Raw_mat' string(product_Mix') string(Raw_avail') ]];
+disp(table);
+input('Enter to proceed ') ;
+
+for i = 1:Nproducts
+ A(i,:) = product_Mix(:,i)';
+ b(i) = Raw_avail(i);
+end
+
+// market restriction
+A = [A;[-1 1;-1 -1]];
+b = [b(:);1;-6];
+lb = zeros(1,Nproducts);
+ub = [%inf %inf];
+C = profit_product;
+
+[xopt,fopt,exitflag,output,lambda] = linprog(-C',A,b,[],[],lb,ub);
+clc
+select exitflag
+ //Display result
+case 0 then
+ mprintf('Optimal Solution Found')
+ input('Press enter to view results')
+ disp('Paint produced')
+ mprintf('\nExterior paint %d\t interior paint %d',xopt(1),xopt(2));
+case 1 then
+ mprintf('Primal Infeasible')
+ y = A*xopt-b;
+ if sum(y(1:Nrawmaterial))>0
+ mprintf('\nInsufficient raw material');
+ else
+ mprintf('\nCan not meet market constraint');
+ end
+case 2 then
+ mprintf('Dual Infeasible')
+case 3
+ mprintf('Maximum Number of Iterations Exceeded. Output may not be optimal')
+case 4
+ mprintf('Solution Abandoned')
+case 5
+ mprintf('Primal objective limit reached')
+else
+ mprintf('Dual objective limit reached')
+end
+
diff --git a/code/linprog/TOOLCO.sce b/code/linprog/TOOLCO.sce
new file mode 100644
index 0000000..c14ca1b
--- /dev/null
+++ b/code/linprog/TOOLCO.sce
@@ -0,0 +1,82 @@
+//This is an infeasible model
+//Ref:H.A. TAHA,"OPERATIONS RESEARCH AN INTRODUCTION",PEARSON-Prentice Hall New Jersey 2007,chapter 3.5
+//Example:
+//Toolco produces three types of tools, T1,T2 and T3. The tools use two rawmaterials, M1 and M2, according to the data in the following table:
+//--------------------------------------------------------------------
+// Number of units of raw materials per tool
+// -----------------------------------------
+//Raw material T1 T2 T2
+//---------------------------------------------------------------------
+//M1 3 5 6
+//M2 5 3 4
+//---------------------------------------------------------------------
+//The available daily quantites of raw materials M1 and M2 are 1000 units and 1200 units, respectively. The marketing department informed the production manager that according to their research , the daily demand for all three tools must be at least 500 units. will the manufacturing department be able to satisfy the demand?
+
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:Debasis Maharana
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//======================================================================
+clc;
+
+Nraw = 2;
+Nproduct = 3;
+Product_mix = [3 5 6;5 3 4];
+Raw_avail = [1000 1200];
+Demand = [500 500 500];
+
+mprintf('Data received')
+mprintf('Number of product %d',Nproduct);
+mprintf('Number of Raw materials %d',Nraw);
+FirstR = ['Product 1','Product 2','Product 3','Available']
+Raw_mat = ['M1','M2'];
+
+table = [['Raw materisl' FirstR];[Raw_mat' string(Product_mix) string(Raw_avail') ]];
+disp(table);
+input('Enter to proceed ');
+
+for i = 1:Nraw
+ A(i,:) = Product_mix(i,:);
+ b(i) = Raw_avail(i);
+end
+A = [A;-eye(Nproduct,Nproduct)];
+b = [b;-500*ones(Nproduct,1)];
+
+lb = zeros(1,Nproduct);//Redudant due to demand
+ub = [];
+C = ones(1,Nproduct);
+[xopt,fopt,exitflag,output,lambda] = linprog(-C',A,b,[],[],lb,ub);
+
+clc
+select exitflag
+ //Display result
+case 0 then
+ mprintf('Optimal Solution Found')
+ input('Press enter to view results')
+ disp('Paint produced')
+ mprintf('\nExterior paint %d\t interior paint %d',xopt(1),xopt(2));
+case 1 then
+ mprintf('Primal Infeasible\n')
+ y = A*xopt-b;
+ if sum(y(1:Nraw))>0
+ mprintf('\nInsufficient raw material');
+ else
+ mprintf('\nCan not meet market demand');
+ end
+case 2 then
+ mprintf('Dual Infeasible')
+case 3
+ mprintf('Maximum Number of Iterations Exceeded. Output may not be optimal')
+case 4
+ mprintf('Solution Abandoned')
+case 5
+ mprintf('Primal objective limit reached')
+else
+ mprintf('Dual objective limit reached')
+end
+
diff --git a/code/linprog/TOYCO Dual.sce b/code/linprog/TOYCO Dual.sce
new file mode 100644
index 0000000..8fdba97
--- /dev/null
+++ b/code/linprog/TOYCO Dual.sce
@@ -0,0 +1,88 @@
+//This example shows the use of duality theorm to determine the reduced cost associated with the non-negative constraints
+//Ref:H.A. TAHA,"OPERATIONS RESEARCH AN INTRODUCTION",PEARSON-Prentice Hall New Jersey 2007,chapter 2.1
+//Example:
+//TOYCO assembels three types of toys-trains,trucks and cars using three operations. the daily limits on the available times for the three operations are 430,460 and 420 minutes respectively. The revenues per unit of toy train, truck and car are $3.$2 and $5 respectively. The corrosponding times per train and per car are (2,0,4) and (1,2,0) minutes ( a zero time indicates that the operation is not used). determine the . Determine the shadow pricing and how optima changes with resource change.
+
+//The primal model of the above problem is
+//maximize z = 3*x1 + 2*x2 + 5*x3
+//Subject to
+//x1 + 2*x2 + x3 <=430
+//3*x1 +2*x3 <=460
+//x1 + 4*x2 <=420
+//x1,x2,x3 >= 0
+
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:Debasis Maharana
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//=================================================================================
+
+clc;
+
+Nproducts = 3;
+Noperations = 3;
+revenue = [3 2 5];
+resource = [430 460 420];
+Assembly_time = [1 3 1;2 0 4;1 2 0];
+mprintf('Data Received')
+prodNam = ['Trains','Trucks','cars']';
+Operation = ['Operation 1','Operation 2','Operation 3'];
+table = [['Products',Operation,'Revenue'];[prodNam,string(Assembly_time),string(revenue)'];['Resource',string(resource),'']];
+disp(table)
+input('Press enter to proceed ')
+//primal model constraints
+A = Assembly_time';
+b = resource';
+
+//dual constraints
+dualA = -A';
+[Ncons,Nvars] = size(A);
+for i = 1:Nvars
+ A1(i,i) = 1;
+end
+dualAeq = [dualA A1];
+dualbeq = -revenue';
+C = [b;zeros(Nvars,1)];
+lb= zeros(1,2*Nvars);
+ub = [];
+[xopt,fopt,exitflag,output,lambda] = linprog(C,[],[],dualAeq,dualbeq,lb,[]);
+
+clc;
+select exitflag
+ //Display result
+case 0 then
+ mprintf('Optimal Solution Found');
+ input('Press enter to view results');clc;
+ mprintf('Revenue Generated %d\n',fopt);
+ disp(xopt(1:Ncons)','Dual values of the primal constraints');
+ disp(xopt(Ncons+1:Ncons+Nvars)','Dual values of each primal variable');
+ for i = 1:Ncons
+ mprintf('\n A cost decrease of %d will occur in the current objective cost value per unit decrease in resource %d ',xopt(i),i)
+ end
+ for i = 1:Nvars
+ mprintf('\n A cost decrease of %d will occur in the current objective cost value per unit increase in variable x%d ',xopt(Ncons+i),i)
+ end
+
+case 1 then
+ mprintf('Primal Infeasible')
+case 2 then
+ mprintf('Dual Infeasible')
+case 3
+ mprintf('Maximum Number of Iterations Exceeded. Output may not be optimal')
+case 4
+ mprintf('Solution Abandoned')
+case 5
+ mprintf('Primal objective limit reached')
+else
+ mprintf('Dual objective limit reached')
+end
+
+
+
+
+
diff --git a/code/linprog/TOYCO model.sce b/code/linprog/TOYCO model.sce
new file mode 100644
index 0000000..b6ea553
--- /dev/null
+++ b/code/linprog/TOYCO model.sce
@@ -0,0 +1,67 @@
+//This example shows the use of slack or surplus variables and their sigificance on the model
+//Ref:H.A. TAHA,"OPERATIONS RESEARCH AN INTRODUCTION",PEARSON-Prentice Hall New Jersey 2007,chapter 2.1
+//Example:
+//TOYCO assembels three types of toys-trains,trucks and cars using three operations. the daily limits on the available times for the three operations are 430,460 and 420 minutes respectively. The revenues per unit of toy train, truck and car are $3.$2 and $5 respectively. The corrosponding times per train and per car are (2,0,4) and (1,2,0) minutes ( a zero time indicates that the operation is not used). determine the optimum production rate to maximize profit. Check any surplus resource availability.
+
+// Copyright (C) 2018 - IIT Bombay - FOSSEE
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author:Debasis Maharana
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//=================================================================================
+
+clc;
+
+Nproducts = 3;
+Noperations = 3;
+revenue = [3 2 5];
+resource = [430 460 420];
+Assembly_time = [1 3 1;2 0 4;1 2 0];
+mprintf('Data Received')
+prodNam = ['Trains','Trucks','cars']';
+Operation = ['Operation 1','Operation 2','Operation 3'];
+table = [['Products',Operation,'Revenue'];[prodNam,string(Assembly_time),string(revenue)'];['Resource',string(resource),'']];
+disp(table)
+input('Press enter to proceed ')
+
+NequalCon = Noperations;
+Aeq = zeros(NequalCon,Nproducts+Noperations);
+for i = 1:Noperations
+ Aeq(i,1:Nproducts) = Assembly_time(:,i)';
+ beq(i) = resource(i);
+ Aeq(i,i+Nproducts) = 1;
+end
+
+C = -[revenue zeros(1,Nproducts)];
+lb= zeros(1,2*Noperations);
+ub = [];
+
+[xopt,fopt,exitflag,output,lambda] = linprog(C',[],[],Aeq,beq,lb,[]);
+clc;
+select exitflag
+ //Display result
+case 0 then
+ mprintf('Optimal Solution Found');
+ input('Press enter to view results');clc;
+ mprintf('Revenue Generated %d\n',-fopt);
+ disp(xopt(1:Nproducts)','Optimal Number of Trains Trucks and Cars');
+ disp(xopt(Nproducts+1:Nproducts+NequalCon)','Surplus resource available among 3 resources');
+ beq = beq-xopt(Nproducts+1:Nproducts+NequalCon);
+ disp(beq','Minimum Constraint boundry for Current optima');
+case 1 then
+ mprintf('Primal Infeasible')
+case 2 then
+ mprintf('Dual Infeasible')
+case 3
+ mprintf('Maximum Number of Iterations Exceeded. Output may not be optimal')
+case 4
+ mprintf('Solution Abandoned')
+case 5
+ mprintf('Primal objective limit reached')
+else
+ mprintf('Dual objective limit reached')
+end