summaryrefslogtreecommitdiff
path: root/code/linprog/TOYCO model.sce
blob: b6ea553a4d9e6b8c02ebd7eecbe01b9a1bf81933 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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