Scilab---FOSSEE-Optimisation-Toolbox/C2/Constrained-Optimisation-using-FOT/English

From Script | Spoken-Tutorial
Revision as of 09:25, 16 November 2021 by Nancyvarkey (Talk | contribs)

Jump to: navigation, search

Title of the script: Constrained Optimisation using fot_fmincon and fot_intfmincon functions

Author: Siddharth Agarwal and Mankrit Singh

Keywords: FOSSEE Optimization Toolbox, Integer Constrained Optimisation, Constrained Optimisation, OR, fot_fmincon, fot_intfmincon .

Visual Cue Narration

Show Slide

Title Slide

Welcome to the spoken tutorial on Constrained Optimisation.

Show Slide

Learning Objectives

In this tutorial, we will learn how to:

  • Use fot underscore fmincon and fot underscore intfmincon functions in Scilab

  • Solve constrained optimisation problems using fot underscore fmincon and fot underscore intfmincon

Show Slide

System Requirements

To record this tutorial, I am using,

  • Ubuntu 18.04

  • Scilab 6.1.0 and

  • 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 optimization and Scilab

If not, for relevant tutorials please visit this site.

Show Slide

Code Files

  • The files used in this tutorial are 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 the Constrained Optimisation problem?

A constrained nonlinear optimisation problem is a mathematical optimisation model.

It has:

  • A linear or nonlinear objective function

  • Bounds on the decision variables

  • Linear and nonlinear constraints on decision variables

Show Slide

Mathematical Formulation

where f , A, b, Aeq, beq, c,

ceq, lb, and ub are given.

A general form of constrained nonlinear optimisation problem is as shown.

Show Slide

Example

We will now solve this example to illustrate the use of fot underscore fmincon.

In this example, we will learn how to:

  • Minimize the given function

Note that the objective function is nonlinear.

The example has 4 variables x1, x2, x3 and x4.

There are bounds on the variables, but no constraints otherwise.

Show Slide

Example

I have downloaded the required files to my Downloads folder.
Open the Scilab window >> place the cursor on the Scilab console. Now open the Scilab console.
Type editor >> press Enter.

In the Scilab console type editor and press Enter.

Editor window opens.

Click on File >> Open button >> locate the file opt_fmincon .sce.

Video-editor: Pls put a textbox on screen. “In Windows OS ,Click on Open button”

Click on the Open button on the toolbar and locate the file opt_fmincon.sce.

Then click the Ok button.

opt_fmincon.sce file opens in the editor.

Show opt_fmincon .sce in scilab editor. Now we will see the input arguments for fot underscore fmincon.
Highlight ‘f’ f is the objective function that has to be minimized.
Highlight ‘x0’ x0 is a vector with the initial values of the decision variables.
Highlight the line with ‘A’

A is a matrix of coefficients of linear inequality constraints.

Highlight the line with ‘b’

b is a vector of the right-hand side of linear inequality constraints.

Highlight ‘lb’ and ub

lb and ub are the row vectors.

They contain the lower and upper bounds of the decision variables respectively.

Highlight ‘Nonlinearcon’

‘Nonlinearcon’ is a Scilab function.

It represents the equality and inequality nonlinear constraints for the problem.

Highlight Output Arguments

Now we will see the output arguments.

Output arguments are xopt, fopt, exitflag, output, lambda, gradient, hessian.

Highlight ‘xopt’ xopt is the optimal value of x.
Highlight ‘fopt’ fopt is the optimal objective function value.
Highlight ‘exitflag’ exitflag is the status of execution.
Highlight ‘output’ Output is a structure containing detailed information about the optimization.
Highlight ‘lambda’

Lambda is a structure containing the following:

Lagrange multipliers of the lower bounds and upper bounds.

Linear equality and inequality constraints at the optimized point.

Highlight ‘gradient’ Gradient is a vector containing the objective's gradient of the solution.
Highlight ‘hessian’ Hessian is a matrix containing the Hessian of Lagrangian at the solution.

Highlight

[xopt,fopt,exitflag,output, lambda,gradient, hessian] = fot_fmincon(ObjectiveFunction,x0,A,b,[],[],lb,ub,Nonlinearcon)

Here we see the Scilab code to define and solve the example.

We call the fot underscore fmincon function to solve the given problem.

Press CTRL + s

Click on execute button on scilab

Click on File with Echo

Save the file by pressing Control and S keys simultaneously.

To run the file, click on the Execute menu.

Click on File with Echo from the drop down.

Point to the Confirmation box.

Click Yes to confirm.

A confirmation box to clear the Console appears.

Click on the Yes button to confirm.

Change the window to Scilab console

Switch to the Scilab console to see the output.

We see that it prints the fopt value, xopt values, exitflag, output, lambda, gradient, and hessian on the Scilab console.

We will now close the Scilab editor window.

Show Slide

Integer Constraints

We will now look at constrained integer nonlinear programming problems.

These are problems in which some decision variables are constrained to be integers.

Show Slide

Mathematical Formulation

A general form of the constrained integer optimisation problem is as shown.

Show Slide

Example

We will now solve this example to illustrate the use of fot underscore intfmincon

In this example, we will demonstrate how to minimize the given function.

Note that some of the decision variables are constrained to be integers.

Let’s use the previous example with added integer constraints on the variables x1 and x2.

We will use the toolbox to solve this example.

Show opt_intfmincon.sce in Scilab editor.

Open the Scilab console.

Type editor on the Scilab console and press Enter.

Open opt_intfmincon.sce in the Scilab editor.

Show opt_intfmincon.sce in scilab editor.

We have the same input arguments that we had in opt_fmincon.sce.

f,x0,A,b,lb,ub and Nonlinearcon


Along with them we have an additional input argument called as intcon.

Highlight ‘intcon’ intcon is a vector of the indices of integer variables.
Highlight Output Arguments

Now we will see the output arguments.

We have the same output arguments that we had in opt_fmincon.sce

Output arguments are xopt, fopt, exitflag, gradient, hessian

Highlight [xopt,fopt,exitflag,gradient,hessian] = fot_intfmincon(ObjectiveFunction,x0,int,A,b,[],[],lb,ub,Nonlinearcon) This is how we call fot underscore intfmincon function.

Press CTRL + s

Click on execute button on scilab

Save the file by pressing Control and S keys simultaneously.

To run the file, click on the Execute menu.

Click on File with Echo from the drop down.

Point to the Confirmation box.

Click Yes to confirm.

A confirmation box to clear the Console appears.

Click on the Yes button to confirm.

Change the window to Scilab console Switch to the Scilab console to see the output.
Highlight Outputs We see that it prints the fopt value, xopt values, exitflag, output, lambda, gradient, and hessian in the Scilab console.

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 fmincon and fot underscore intfmincon functions of the FOSSEE Optimization Toolbox.

  • Solve constrained nonlinear programming examples in Scilab.

Show Slide

Assignment

As an assignment:

  • Minimise the following objective function subject to the given constraints

  • The optimal value will be 75728.822 and optimal solution will be x one equal to 3.1692029 and x two equal to 6.3384058

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:

Acknowledgement

Spoken Tutorial and FOSSEE projects are funded by MoE, 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