Scilab---FOSSEE-Optimisation-Toolbox/C2/Linear-Programming-using-linprog-function/English

From Script | Spoken-Tutorial
Revision as of 15:58, 20 December 2021 by Mankrits (Talk | contribs)

Jump to: navigation, search

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:

  • Solve linear programming problems using fot underscore linprog function in Scilab.
  • Use fot underscore linprog function of FOSSEE Optimization Toolbox.

Show Slide

System requirement

To record this tutorial, I am using

  • Ubuntu 18.04
  • Scilab 6.1.0
  • FOSSEE Optimization Toolbox version 0.4.1.

Show Slide

Pre-requisites

https://spoken-tutorial.org

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.

Show Slide

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

What is Linear Programming?

What is Linear Programming?
  • A function is linear, if it has a degree of one or zero.
  • A linear program is a mathematical optimization model with:
    • Linear objective function
    • Linear constraints

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:

  • Minimize the given function subject to these given constraints and bounds.

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:

  • linear programming problems and
  • mixed integer programming problems

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.

  • There are cases when the optimal value is unbounded.
  • The minimum value may go to negative infinity in the absence of suitable constraints.

Show Slide

Unbounded Problems II

Such problems are called Unbounded problems.

Show Slide

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

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.

  • 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 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:

  • Use fot underscore linprog function of the FOSSEE Optimization Toolbox.
  • Solve an LP example using fot underscore linprog in Scilab.

Show Slide

Assignment

Highlight the constraint

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

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.

Contributors and Content Editors

Mankrits, Nancyvarkey