Difference between revisions of "Scilab---FOSSEE-Optimisation-Toolbox/C2/Linear-Programming-using-linprog-function/English"
Nancyvarkey (Talk | contribs) |
|||
Line 23: | Line 23: | ||
In this tutorial, we will learn how to: | In this tutorial, we will learn how to: | ||
− | + | *Solve '''linear programming''' problems using '''fot underscore linprog function''' in '''Scilab'''. | |
− | + | *Use '''fot underscore linprog function''' of '''FOSSEE Optimization Toolbox.''' | |
− | + | ||
|- | |- | ||
| | | | ||
Line 34: | Line 33: | ||
To record this tutorial, I am using | To record this tutorial, I am using | ||
− | + | *'''Ubuntu 18.04''' | |
− | + | *'''Scilab 6.1.0''' and | |
− | + | *'''FOSSEE Optimization Toolbox''' version 0.4.1. | |
− | + | ||
|- | |- | ||
| | | | ||
Line 48: | Line 46: | ||
To follow this tutorial, you should | To follow this tutorial, you should | ||
− | + | *Install '''FOSSEE Optimization Toolbox''' version '''0.4.1''' or above | |
− | + | *Have basic understanding of '''Scilab''' and optimization theory | |
− | + | *If not, for relevant tutorials please visit this site. | |
− | + | ||
|- | |- | ||
| | | | ||
Line 58: | Line 55: | ||
'''Code Files''' | '''Code Files''' | ||
| | | | ||
− | + | *The files used in this tutorial have been provided in the '''Code files''' link. | |
− | + | *Please download and extract the files. | |
− | + | *Make a copy and then use them while practising. | |
− | + | ||
|- | |- | ||
| | | | ||
Show Slide | Show Slide | ||
− | '''What is Linear Programming ?''' | + | '''What is Linear Programming?''' |
− | | | + | |'''What is Linear Programming?''' |
− | A '''function''' is '''linear,''' if it has a degree of one or zero. | + | *A '''function''' is '''linear,''' if it has a degree of one or zero. |
− | + | *A '''linear program''' is a mathematical '''optimization model''' with: | |
− | A '''linear program''' is a mathematical '''optimization''' | + | **'''Linear objective function''' |
− | + | **'''Linear constraints''' | |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
Line 80: | Line 73: | ||
'''Mathematical Formulation''' | '''Mathematical Formulation''' | ||
− | | A | + | | A general form of the '''Linear Program''' is as shown. |
|- | |- | ||
| | | | ||
Line 91: | Line 84: | ||
In this example, we will learn how to: | In this example, we will learn how to: | ||
− | + | *Minimize the given '''function''' subject to these given constraints and bounds. | |
− | + | ||
− | Note that the '''objective function''' and | + | Note that the '''objective function''' and constraints are '''linear'''. |
|- | |- | ||
| | | | ||
Line 100: | Line 92: | ||
'''Example''' | '''Example''' | ||
− | | I have downloaded the opt_linprog.sce file to my '''Downloads''' folder. | + | | I have downloaded the '''opt_linprog.sce''' file to my '''Downloads''' folder. |
|- | |- | ||
| Cursor on the Scilab console. | | Cursor on the Scilab console. | ||
Line 112: | Line 104: | ||
|- | |- | ||
| | | | ||
− | Click on Open button | + | Click on Open button >> locate the file '''opt_linprog.sce'''. |
Click on the Ok button | Click on the Ok button | ||
| | | | ||
− | Click on the '''Open''' button on the | + | Click on the '''Open''' button on the '''toolbar''' and locate the file '''opt_linprog.sce'''. |
Then click the '''Ok''' button. | Then click the '''Ok''' button. | ||
Line 123: | Line 115: | ||
|- | |- | ||
| Show '''opt_linprog.sce''' in scilab editor. | | Show '''opt_linprog.sce''' in scilab editor. | ||
− | | Now we will see the input arguments for '''fot underscore linprog'''. | + | | Now we will see the '''input arguments''' for '''fot underscore linprog'''. |
|- | |- | ||
| Highlight the line with '''‘c’''' | | Highlight the line with '''‘c’''' | ||
− | | '''''c''''' is a '''vector''' of '''coefficients''' in the '''objective function''' | + | | '''''c''''' is a '''vector''' of '''coefficients''' in the '''objective function'''. |
|- | |- | ||
| Highlight the line with '''‘A’''' | | Highlight the line with '''‘A’''' | ||
− | | | + | |'''''A''''' is a '''matrix''' of '''coefficients''' of '''inequality''' constraints. |
− | '''''A''''' is a '''matrix''' of '''coefficients''' of | + | |
− | + | ||
− | '''inequality''' constraints | + | |
|- | |- | ||
| Highlight the line with '''‘b’''' | | Highlight the line with '''‘b’''' | ||
− | | | + | |'''''b''''' is a '''vector''' of the right-hand side of '''inequality''' constraints. |
− | '''''b''''' is a '''vector''' of the right-hand side | + | |
− | + | ||
− | of '''inequality | + | |
|- | |- | ||
| Highlight the line with '''‘Aeq’''' | | Highlight the line with '''‘Aeq’''' | ||
− | | '''''‘Aeq’''''' is a '''matrix''' of '''coefficients''' of '''equality | + | | '''''‘Aeq’''''' is a '''matrix''' of '''coefficients''' of '''equality''' constraints. |
|- | |- | ||
| Highlight the line with '''‘beq’''' | | Highlight the line with '''‘beq’''' | ||
− | | '''''‘beq’''''' is a '''vector''' of the right-hand side of '''equality | + | | '''''‘beq’''''' is a '''vector''' of the right-hand side of '''equality''' constraints. |
|- | |- | ||
| Highlight the line with '''‘lb’''' | | Highlight the line with '''‘lb’''' | ||
− | | '''''‘lb’''''' is a vector of lower bounds on '''''x''''' | + | | '''''‘lb’''''' is a '''vector''' of lower bounds on '''''x'''''. |
|- | |- | ||
| Highlight the line with '''‘ub’''' | | Highlight the line with '''‘ub’''' | ||
− | | '''''‘ub’''''' is a vector of '''upper bounds''' on '''''x'''''. | + | | '''''‘ub’''''' is a '''vector''' of '''upper bounds''' on '''''x'''''. |
|- | |- | ||
| | | | ||
− | | | + | |Now we will summarize the '''output arguments'''. |
− | Now we will summarize the output arguments | + | |
− | + | '''Output arguments''' are '''''xopt, fopt, exitflag, output,''''' '''lambda''' | |
|- | |- | ||
| Highlight '''‘xopt’''' | | Highlight '''‘xopt’''' | ||
Line 163: | Line 148: | ||
|- | |- | ||
| Highlight '''‘fopt’''' | | Highlight '''‘fopt’''' | ||
− | | '''''fopt''''' is the optimal | + | | '''''fopt''''' is the optimal '''objective function''' value. |
|- | |- | ||
| Highlight '''‘exitflag’''' | | Highlight '''‘exitflag’''' | ||
− | | '''''exitflag''''' denotes the status of execution | + | | '''''exitflag''''' denotes the status of '''execution'''. |
|- | |- | ||
| Highlight '''‘output’''' | | Highlight '''‘output’''' | ||
− | | '''''Output''' is a'' '''structure''' containing detailed information about the optimization. | + | | '''''Output''' is a'' '''structure''' containing detailed information about the '''optimization'''. |
|- | |- | ||
| Highlight '''‘lambda’''' | | Highlight '''‘lambda’''' | ||
− | | '''Lambda''' is a '''structure''' containing '''Lagrange multipliers''' at the optimal solution | + | | '''Lambda''' is a '''structure''' containing '''Lagrange multipliers''' at the optimal solution. |
|- | |- | ||
| Highlight the line calling ‘'''fot_linprog’''' | | Highlight the line calling ‘'''fot_linprog’''' | ||
− | | We will use the '''fot underscore linprog''' | + | | We will use the '''fot underscore linprog function''' to solve the example. |
|- | |- | ||
| | | | ||
Press '''CTRL + S''' | Press '''CTRL + S''' | ||
− | + | Click on the '''Execute''' button on scilab. | |
− | + | Select '''File with Echo''' from the drop-down. | |
− | + | |Save the file by pressing '''Control''' and '''‘S’''' keys simultaneously. | |
− | + | ||
− | + | ||
− | | | + | |
− | Save the file by pressing '''Control''' and '''‘S’''' keys simultaneously. | + | |
To '''run''' the file, click on the '''Execute''' menu. | To '''run''' the file, click on the '''Execute''' menu. | ||
− | Then click on ''' | + | Then click on '''File with Echo''' from the dropdown. |
|- | |- | ||
| | | | ||
Line 208: | Line 189: | ||
Highlight '''‘lambda''' values'''’''' | Highlight '''‘lambda''' values'''’''' | ||
− | | | + | |Switch to the '''Scilab console''' to see the '''output'''. |
− | Switch to the '''Scilab console''' to see the output. | + | |
− | Optimal solutions for the following are displayed on the '''Scilab console'''. | + | '''Optimal solutions''' for the following are displayed on the '''Scilab console'''. |
'''xopt''' values | '''xopt''' values | ||
Line 227: | Line 207: | ||
'''Alternate Input Arguments''' | '''Alternate Input Arguments''' | ||
− | | Now we see an alternate way of | + | | Now we see an alternate way of '''pass'''ing '''input arguments''' to '''fot underscore linprog.''' |
|- | |- | ||
| | | | ||
Line 240: | Line 220: | ||
'''file''' is a '''string''' stating the path of the '''mps file'''. | '''file''' is a '''string''' stating the path of the '''mps file'''. | ||
− | '''MPS | + | '''MPS (Mathematical Programming System)''' is a file format. |
|- | |- | ||
| | | | ||
Line 251: | Line 231: | ||
It is used to present and archive: | It is used to present and archive: | ||
− | + | *'''linear programming''' problems and | |
− | + | *'''mixed integer programming''' problems | |
− | + | ||
− | '''param''' is a list containing parameters to be set. | + | '''param''' is a list containing '''parameters''' to be '''set'''. |
|- | |- | ||
| | | | ||
Line 264: | Line 243: | ||
The problem we just saw was directly solvable using '''fot underscore linprog. ''' | The problem we just saw was directly solvable using '''fot underscore linprog. ''' | ||
− | + | *There are cases when the '''optimal value''' is unbounded. | |
− | + | *The minimum value may go to '''negative infinity''' in the absence of suitable '''constraints'''. | |
− | + | ||
|- | |- | ||
| | | | ||
Line 272: | Line 250: | ||
'''Unbounded Problems II''' | '''Unbounded Problems II''' | ||
− | | | + | |Such problems are called '''Unbounded''' problems. |
− | + | ||
− | + | ||
|- | |- | ||
| | | | ||
Line 281: | Line 257: | ||
'''Infeasible Problems''' | '''Infeasible Problems''' | ||
| | | | ||
− | + | *There are instances where no solution exists for all the constraints. | |
− | + | *These problems are called '''Infeasible''' problems. | |
− | + | ||
We will see an example of these | We will see an example of these | ||
− | constraints on Scilab. | + | constraints on '''Scilab'''. |
|- | |- | ||
| | | | ||
Line 298: | Line 273: | ||
Select '''File with Echo''' option | Select '''File with Echo''' option | ||
| | | | ||
− | We will now change the previous problem | + | We will now change the previous problem to make it '''infeasible'''. |
− | + | ||
− | to make it '''infeasible'''. | + | |
− | + | *Locate the line that defines '''ub''' | |
− | + | *Change the second element of '''ub''' to 0 | |
− | + | *Click on the '''Execute''' menu, | |
− | + | *Click on '''File with Echo''' from the drop down | |
− | + | ||
− | This will execute the ''' | + | This will execute the '''Scilab code.''' |
|- | |- | ||
| | | | ||
Line 315: | Line 287: | ||
Highlight the message '''Primal Infeasible''' | Highlight the message '''Primal Infeasible''' | ||
| | | | ||
− | Switch to the Scilab console to see the output. | + | Switch to the '''Scilab console''' to see the '''output'''. |
The '''console''' shows that the problem is '''Primal Infeasible.''' | The '''console''' shows that the problem is '''Primal Infeasible.''' | ||
Line 330: | Line 302: | ||
In this tutorial, we have learnt how to: | In this tutorial, we have learnt how to: | ||
− | + | *Use '''fot underscore linprog''' function of the '''FOSSEE Optimization Toolbox'''. | |
− | + | *Solve an '''LP''' example using '''fot underscore linprog''' in '''Scilab'''. | |
− | + | ||
|- | |- | ||
| | | | ||
Line 343: | Line 314: | ||
As an assignment: | As an assignment: | ||
− | + | *Solve the same example that we '''executed''', with this additional constraint. | |
− | + | *The optimal value will be -0.5714 and optimal solution will be 0.2857 and 0.8571 | |
− | + | *These are the optimal values of '''x1''' and '''x2''' | |
− | + | ||
|- | |- | ||
| | | | ||
Line 399: | Line 369: | ||
'''Acknowledgment''' | '''Acknowledgment''' | ||
− | | '''Spoken | + | | '''Spoken Tutorial''' and '''FOSSEE projects''' are funded by '''MoE, the Government of India'''. |
|- | |- | ||
| | | |
Revision as of 18:53, 1 November 2021
Title of script: Linear Programming using fot_linprog function
Author: Rupak Rokade, Siddharth Agarwal, Georgey John and Mankrit Singh
Keywords:Scilab console, FOSSEE Optimization Toolbox, Linear Programming, OR, Operations Research, fot_linprog, constraints, input, output, video tutorial.
Visual Cue | Narration |
---|---|
Show Slide Title Slide |
Hello and welcome to the spoken tutorial on “Linear Programming using fot underscore linprog function”. |
Show Slide Learning Objectives |
In this tutorial, we will learn how to:
|
Show Slide System requirement |
To record this tutorial, I am using
|
Show Slide Pre-requisites |
To follow this tutorial, you should
|
Show Slide Code Files |
|
Show Slide What is Linear Programming? |
What is Linear Programming?
|
Show Slide Mathematical Formulation |
A general form of the Linear Program is as shown. |
Show Slide Example |
We will now solve this example to illustrate the use of fot underscore linprog. In this example, we will learn how to:
Note that the objective function and constraints are linear. |
Show Slide Example |
I have downloaded the opt_linprog.sce file to my Downloads folder. |
Cursor on the Scilab console. | I have opened the Scilab console. |
Type editor >> press Enter. |
In the Scilab console, type editor and press Enter. Editor window opens. |
Click on Open button >> locate the file opt_linprog.sce. Click on the Ok button |
Click on the Open button on the toolbar and locate the file opt_linprog.sce. Then click the Ok button. opt_linprog.sce file opens in the editor. |
Show opt_linprog.sce in scilab editor. | Now we will see the input arguments for fot underscore linprog. |
Highlight the line with ‘c’ | c is a vector of coefficients in the objective function. |
Highlight the line with ‘A’ | A is a matrix of coefficients of inequality constraints. |
Highlight the line with ‘b’ | b is a vector of the right-hand side of inequality constraints. |
Highlight the line with ‘Aeq’ | ‘Aeq’ is a matrix of coefficients of equality constraints. |
Highlight the line with ‘beq’ | ‘beq’ is a vector of the right-hand side of equality constraints. |
Highlight the line with ‘lb’ | ‘lb’ is a vector of lower bounds on x. |
Highlight the line with ‘ub’ | ‘ub’ is a vector of upper bounds on x. |
Now we will summarize the output arguments.
Output arguments are xopt, fopt, exitflag, output, lambda | |
Highlight ‘xopt’ | xopt is the optimal value of x. |
Highlight ‘fopt’ | fopt is the optimal objective function value. |
Highlight ‘exitflag’ | exitflag denotes the status of execution. |
Highlight ‘output’ | Output is a structure containing detailed information about the optimization. |
Highlight ‘lambda’ | Lambda is a structure containing Lagrange multipliers at the optimal solution. |
Highlight the line calling ‘fot_linprog’ | We will use the fot underscore linprog function to solve the example. |
Press CTRL + S Click on the Execute button on scilab. Select File with Echo from the drop-down. |
Save the file by pressing Control and ‘S’ keys simultaneously.
To run the file, click on the Execute menu. Then click on File with Echo from the dropdown. |
Change the window to Scilab console Highlight Optimal solution Highlight ‘xopt values’ Highlight ‘fopt value’ Highlight ‘exitflag value’ Highlight ‘output values’ Highlight ‘lambda values’ |
Switch to the Scilab console to see the output.
Optimal solutions for the following are displayed on the Scilab console. xopt values fopt value exitflag output and lambda. |
Show Slide Alternate Input Arguments |
Now we see an alternate way of passing input arguments to fot underscore linprog. |
Show Slide Alternate Input Arguments Highlight ‘file’ Highlight ‘MPS’ |
file is a string stating the path of the mps file. MPS (Mathematical Programming System) is a file format. |
Show Slide Alternate Input Arguments Highlight ‘param’ |
It is used to present and archive:
param is a list containing parameters to be set. |
Show Slide Unbounded Problems I |
The problem we just saw was directly solvable using fot underscore linprog.
|
Show Slide Unbounded Problems II |
Such problems are called Unbounded problems. |
Show Slide Infeasible Problems |
We will see an example of these constraints on Scilab. |
Switch to the scilab editor. Replace the value. Click on the Execute menu Select File with Echo option |
We will now change the previous problem to make it infeasible.
This will execute the Scilab code. |
Switch to the Scilab Console Highlight the message Primal Infeasible |
Switch to the Scilab console to see the output. The console shows that the problem is Primal Infeasible. |
Show Slide Summary |
This brings us to the end of this tutorial. Let us summarise. In this tutorial, we have learnt how to:
|
Show Slide Assignment Highlight the constraint |
As an assignment:
|
Show Slide About Spoken Tutorial Project |
The video at the following link summarises the Spoken Tutorial project. Please download and watch it. |
Show Slide Spoken Tutorial Workshops |
The Spoken Tutorial Project Team conducts workshops and gives certificates. For more details, please write to us |
Show Slide Answers for THIS Spoken Tutorial |
Please post your timed queries in this forum. |
Show Slide: FOSSEE Forum | Please post your general and technical queries on Scilab in this forum. |
Show Slide Textbook Companion project |
The FOSSEE team coordinates the Textbook Companion project. We give Certificates and Honorarium to the contributors. For more details, please visit this site.. |
Show Slide Lab Migration |
The FOSSEE team coordinates the Lab Migration project. For more details, please visit this site. |
Show Slide Acknowledgment |
Spoken Tutorial and FOSSEE projects are funded by MoE, the Government of India. |
Show Slide Thank you |
This is Mankrit Singh, a FOSSEE intern 2021, IIT Bombay signing off Thanks for joining. |