diff options
Diffstat (limited to 'code/Symphonymat')
-rw-r--r-- | code/Symphonymat/Factory planing.sce | 143 | ||||
-rw-r--r-- | code/Symphonymat/Mining.sce | 154 | ||||
-rw-r--r-- | code/Symphonymat/factory.xls | bin | 0 -> 29184 bytes |
3 files changed, 297 insertions, 0 deletions
diff --git a/code/Symphonymat/Factory planing.sce b/code/Symphonymat/Factory planing.sce new file mode 100644 index 0000000..e140f42 --- /dev/null +++ b/code/Symphonymat/Factory planing.sce @@ -0,0 +1,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) + + diff --git a/code/Symphonymat/Mining.sce b/code/Symphonymat/Mining.sce new file mode 100644 index 0000000..f92b93a --- /dev/null +++ b/code/Symphonymat/Mining.sce @@ -0,0 +1,154 @@ +// This is an example of mixed integer linear programming problem. This problem dimension increases significantly with increase in years or mines. +//Example: A mining company is going to continue operating in a certain area for the next five years. There are four mines in this area, but it can operate at most three in any one year. Although a mine may not operate in a certain year, it is still necessary to keep it ‘open’, in the sense that royalties are payable, if it be operated in a future year. Clearly, if a mine is not going to be worked again, it can be permanently closed down and no moreroyalties need be paid. The yearly royalties payable on each mine kept ‘open’ are as follows: +// ----------------- +// Mine 1 £5 million +// Mine 2 £4 million +// Mine 3 £4 million +// Mine 4 £5 million +// ------------------ +//There is an upper limit to the amount of ore, which can be extracted from each mine in a year. These upper limits are as follows: +// --------------------- +// Mine 1 2 × 10^6 tons +// Mine 2 2.5 × 10^6 tons +// Mine 3 1.3 × 10^6 tons +// Mine 4 3 × 10^6 tons +// --------------------- +//The ore from the different mines is of varying quality. This quality is measured on a scale so that blending ores together results in a linear combination of the quality measurements, for example, if equal quantities of two ores were combined, the resultant ore would have a quality measurement half way between that of the ingredient ores. Measured in these units the qualities of the ores from the mines are given as follows: +// --------------- +// Mine 1 1.0 +// Mine 2 0.7 +// Mine 3 1.5 +// Mine 4 0.5 +// --------------- +//In each year, it is necessary to combine the total outputs from each mine to produce a blended ore of exactly some stipulated quality. For each year, these qualities are as follows: +// ------------------- +// Year 1 0.9 +// Year 2 0.8 +// Year 3 1.2 +// Year 4 0.6 +// Year 5 1.0 +// ------------------- +//The final blended ore sells for £10 ton each year. Which mines should be operated each year and how much should they produce? + +// 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 + +Nmines = 4; +//Royltes = [5e6 4e6 4e6 5e6]; +Roylte = [5e6 4e6 4e6 5e6]; + +ubMines = [2e6 2.5e6 1.3e6 3e6]; +Quality = [1 0.7 1.5 0.5]; +Quality_blend = [0.9 0.8 1.2 0.6 1]; +Nyears = length(Quality_blend); +Royltes = Roylte; +for i = 1:Nyears-1 + Roylte = Roylte*0.9; + Royltes = [Royltes Roylte]; +end + + + +mprintf('Received Data') +mprintf('\nNumber of years to operate %d',Nyears) +mprintf('\nNumber of mines %d',Nmines); +disp(Royltes,'Royalities to be paid for each mine',); +disp(ubMines,'Upper limit of ore available from each mine'); +disp(Quality,'Quality of ore from each mine'); +input('Press enter to proceed') + +//i - mine , t - year +A = zeros(1,3*Nyears*Nmines+Nyears) +Aeq_quantity = zeros(Nyears,Nyears*(3*Nmines+1)); +Aeq_quality = zeros(Nyears,Nyears*(3*Nmines+1)); +A_operation = zeros(Nyears,Nyears*(3*Nmines+1)); +Aoutput =[];Aopen=[]; +boutput = zeros(Nyears*Nmines,1); +bopen = zeros(Nyears*Nmines,1); +beq_quantity = zeros(Nyears,1); +beq_quality = zeros(Nyears,1); + +for i = 1:Nyears + Aeq_quantity(i,(i-1)*Nmines+1:i*Nmines) = 1; + Aeq_quantity(i,Nyears*Nmines+i) = -1; + beq_quantity(i) = 0; + + Aeq_quality(i,(i-1)*Nmines+1:i*Nmines) = Quality ; + Aeq_quality(i,Nmines*Nyears+i) = -Quality_blend(i); + beq_quality(i) = 0 + + A_operation(i,Nyears*(Nmines+1)+((i-1)*Nmines+1:i*Nmines)) = 1; + B_operation(i) = 3; + A_output = zeros(Nmines,Nyears*(3*Nmines+1)); + for j = 1:Nmines + A_output(j,(i-1)*Nmines+j) = 1; + A_output(j,Nyears*(Nmines+1)+(i-1)*Nmines+j) = - ubMines(j); + end + Aoutput = [Aoutput;A_output]; + A_open = zeros(Nmines,Nyears*(3*Nmines+1)); + for j = 1:Nmines + A_open(j,(Nmines+1)*Nyears+(i-1)*Nmines+j) = 1; + A_open(j,(2*Nmines+1)*Nyears+(i-1)*Nmines+j) = -1; + end + Aopen = [Aopen;A_open]; +end +Aclose = [];bclose = zeros((Nyears-1)*Nmines,1); +for i = 1:Nyears-1 + A_close = zeros(Nmines,Nyears*(3*Nmines+1)); + for j = 1:Nmines + A_close(j,Nyears*(2*Nmines+1)+(i-1)*Nmines+j) = -1; + A_close(j,Nyears*(2*Nmines+1)+i*Nmines+j) = 1; + end + Aclose = [Aclose;A_close]; +end + +A = [Aoutput;A_operation;Aopen;Aclose] +Aeq = [Aeq_quantity;Aeq_quality]; +b = [boutput;B_operation;bopen;bclose] +beq = [beq_quantity;beq_quality]; + +lb = zeros(1,Nyears*(3*Nmines+1)); +ub = [repmat(ubMines,1,Nyears) sum(ubMines)*ones(1,Nyears) ones(1,2*Nmines*Nyears)]; +//C = [zeros(1,Nmines*Nyears) [10 9 8 7 6].*ones(1,Nyears) zeros(1,Nyears*Nmines) -repmat(Royltes,1,Nyears)]'; +C = [zeros(1,Nmines*Nyears) [10 10*0.9 10*0.9^2 10*0.9^3 10*0.9^4 ].*ones(1,Nyears) zeros(1,Nyears*Nmines) -Royltes]'; + +// All variables are not integers +intcon = [(Nmines+1)*Nyears+1:Nyears*(3*Nmines+1)]; +options = list("time_limit", 2500); +[xopt,fopt,status,output] = symphonymat(-C,intcon,A,b,Aeq,beq,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') + +for i = 1:Nyears + xx(i,:) = xopt((i-1)*Nmines+1:i*Nmines)'; + Qt(i) = xopt(Nmines*Nyears+i); +end +years = string(1:Nyears); +Mines = []; +mprintf('Total profit %d',-fopt); +for i = 1:Nmines + Mines = [Mines strcat(['Mine',string(i)])] +end +table = [['years' Mines];[years' string(xx)]]; +disp(table); +disp(string(Qt),'Each year produced blended ore') diff --git a/code/Symphonymat/factory.xls b/code/Symphonymat/factory.xls Binary files differnew file mode 100644 index 0000000..04b174e --- /dev/null +++ b/code/Symphonymat/factory.xls |