summaryrefslogtreecommitdiff
path: root/code/Symphonymat/Factory planing.sce
blob: e140f4288d9f28fb05d45429cd465f974461378b (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//A practical problem of factory planning which determines the optimum product
// mix subject to production capacity and marketing limitation. 
//This example shows how to use spreadsheet data directly in scilab. 
//Ref: H. Paul Williams ,Model Building in Mathematical Programming ,
//A John Wiley & Sons, Ltd., Publication, Fifth Ed, Chapter 12.
//
//Example: An engineering factory makes seven products (PROD 1 to PROD 7) on the
//following machines: four grinders, two vertical drills, three horizontal drills, one
//borer and one planer. Each product yields a certain contribution to profit (defined
//as £/unit selling price minus cost of raw materials). These quantities (in £/unit)
//together with the unit production times (hours) required on each process are given
//below. A dash indicates that a product does not require a process.
//---------------------------------------------------------------------------------------
//                            Prod 1  Prod 2  Prod 3  Prod 4  Prod 5  Prod 6  Prod 7
//
//Contribution to profit       10       6       8       4       11      9       3
//Grinding                     0.5      0.7     -       -       0.3     0.2     0.5
//Vertical drilling            0.1      0.2     -       0.3     -       0.6     -
//Horizontal drilling          0.2      -       0.8     -       -       -       0.6
//Boring                       0.05     0.03    -       0.07    0.1     -       0.08
//Planing                       -       -       0.01    -       0.05    -       0.05
//--------------------------------------------------------------------------------------
//In the present month (January) and the five subsequent months, certain
//machines will be down for maintenance. These machines will be as follows:
//--------------------------------------------    
//January     1 Grinder
//February    2 Horizontal drills
//March       1 Borer
//April       1 Vertical drill
//May         1 Grinder and 1 Vertical drill
//June        1 Planer and 1 Horizontal drill
//--------------------------------------------
//
//There are marketing limitations on each product in each month. These are
//given in the following table:
//-------------------------------------------
//             1    2   3   4   5    6   7
//-------------------------------------------             
//January     500 1000 300 300 800  200 100
//February    600 500  200 0   400  300 150
//March       300 600  0   0   500  400 100
//April       200 300  400 500 200  0   100
//May         0   100  500 100 1000 300 0
//June        500 500  100 300 1100 500 60
//-------------------------------------------
//
//The factory works at six days a week with two shifts of 8 h each day.
//When and what should the factory make in order to maximise the total profit? 
//This problem considers single period only with no storage

// 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

filepath = 'C:\Users\Iball\Desktop\scilab problems\Date 21-05-2018-Debasis\factory.xls';
[fd,SST,Sheetnames,Sheetpos] = xls_open(filepath);
S = readxls(filepath);
[Contributation,TextInd] = xls_read(fd,Sheetpos(Sheetnames == 'Contributation')); //Sheetpos gives the position of all the sheets
[Available,TextInd] = xls_read(fd,Sheetpos(Sheetnames == 'Available'));
[Failure,TextInd] = xls_read(fd,Sheetpos(Sheetnames == 'Machine Failure'));
[Limitation,TextInd] = xls_read(fd,Sheetpos(Sheetnames == 'Limitation'));
mclose(fd) //close the file

Sheetdata = readxls(filepath);
mprintf('Problem Data received\n')
for i = 1:4
    disp(Sheetnames(i))
    disp(Sheetdata(i))
end
input('press enter to continue')
clc
mprintf('Scilab is solving your problem')
Shift_T = 8;N_shift = 2;N_Workingdys = 24;//Data is fixed according to example. However it can be made as user defined parameter

Wrk_hrs = Shift_T*N_shift*N_Workingdys;

[Nmonth,Nprod] = size(Limitation);

Nprod = Nprod - 1; 
Nmonth = Nmonth - 1;
Ntype = size(Available,'r');

Available = Available(:,2);

Contributation = Contributation(2:Ntype+2,2:Nprod+1);// Extracting the data matrix only
Limitation = Limitation(2:Nmonth+1,2:Nprod+1); 
Failure = Failure(2:Nmonth+1,2:Ntype+1);
Failure(isnan(Failure))=0;

ub = [];
for i = 1:Ntype
    Amonth(i,:) =  Contributation(i+1,:);
    breq(i) = Available(i)*Wrk_hrs;  
end
b = [];A = zeros(Nmonth*Ntype,Nmonth*Nprod);C = [];lb = zeros(1,Nmonth*Nprod);

// Instead of seperate loops, we can use a single loop for determining all the possible variables
for  i = 1:Nmonth
    A((i-1)*Ntype+1:i*Ntype,(i-1)*Nprod+1:i*Nprod) = Amonth;
    B_month = breq - (Failure(i,:))'*Wrk_hrs;
    b = [b;B_month];   
    C = [C;-Contributation(1,:)'];
    ub = [ub Limitation(i,:)];
end

intcon = 1:Nmonth*Nprod; // all production units are integers
options = list("time_limit", 2500);
[xopt,fopt,status,output] = symphonymat(C,intcon,A,b,[],[],lb,ub,options);
clc
select status
case 227 then
    mprintf('Optimal Solution Found')
case 228 then
    mprintf('Maximum CPU Time exceeded')
case 229 then
    mprintf('Maximum Number of Node Limit Exceeded')
else
    mprintf('Maximum Number of Iterations Limit Exceeded')
end
input('Press enter to view results')
// Solution representation
A2 = ['January','Februry','March','April','May','June']';// users can modify it to accept from the excel sheet 
A1 = [" ", 'Prod1','Prod2','Prod3','Prod4','Prod5','Prod6','Prod7'];

for i = 1:Nmonth
    solution(i,:) = string(xopt((i-1)*Nprod+1:i*Nprod)'); 
end

mprintf('Production schedule for all the months')

table = [A1;[A2 solution]];
disp(table)
mprintf('The profit is %d',-fopt)