Difference between revisions of "Scilab---FOSSEE-Optimisation-Toolbox/C2/Constrained-Optimisation-using-FOT/English"
(Created page with "'''Title of the script''': C'''onstrained Optimisation using fot_fmincon and fot_intfmincon functions''' '''Author: Siddharth Agarwal and Mankrit Singh''' '''Keywords: FOSSE...") |
Nancyvarkey (Talk | contribs) |
||
Line 24: | Line 24: | ||
<ul> | <ul> | ||
<li><blockquote><p>Use '''fot underscore fmincon''' and '''fot underscore intfmincon''' functions in '''Scilab'''</p></blockquote></li> | <li><blockquote><p>Use '''fot underscore fmincon''' and '''fot underscore intfmincon''' functions in '''Scilab'''</p></blockquote></li> | ||
− | <li><blockquote><p>Solve | + | <li><blockquote><p>Solve constrained '''optimisation''' problems using '''fot underscore fmincon''' and '''fot underscore intfmincon'''</p></blockquote></li></ul> |
|- | |- | ||
| | | | ||
Line 49: | Line 49: | ||
<ul> | <ul> | ||
<li><blockquote><p>Install '''FOSSEE Optimization Toolbox''' version '''0.4.1''' or above</p></blockquote></li> | <li><blockquote><p>Install '''FOSSEE Optimization Toolbox''' version '''0.4.1''' or above</p></blockquote></li> | ||
− | <li><blockquote><p>Have basic understanding of optimization and Scilab</p></blockquote></li></ul> | + | <li><blockquote><p>Have basic understanding of '''optimization''' and '''Scilab'''</p></blockquote></li></ul> |
If not, for relevant tutorials please visit this site. | If not, for relevant tutorials please visit this site. | ||
Line 67: | Line 67: | ||
'''What is the Constrained Optimisation problem?''' | '''What is the Constrained Optimisation problem?''' | ||
− | | | + | |A constrained nonlinear '''optimisation''' problem is a mathematical '''optimisation model.''' |
− | ''' | + | |
It has: | It has: | ||
<ul> | <ul> | ||
− | <li><blockquote><p> | + | <li><blockquote><p>A linear or nonlinear''' objective function'''</p></blockquote></li> |
<li><blockquote><p>'''Bounds''' on the '''decision variables'''</p></blockquote></li> | <li><blockquote><p>'''Bounds''' on the '''decision variables'''</p></blockquote></li> | ||
− | <li><blockquote><p> | + | <li><blockquote><p>Linear and nonlinear constraints on '''decision variables'''</p></blockquote></li></ul> |
− | |||
− | |||
|- | |- | ||
| | | | ||
Line 88: | Line 85: | ||
'''ceq, lb, and ub are given.''' | '''ceq, lb, and ub are given.''' | ||
− | | A | + | | A general form of constrained nonlinear '''optimisation''' problem is as shown. |
|- | |- | ||
| | | | ||
Line 100: | Line 97: | ||
<ul> | <ul> | ||
− | <li><blockquote><p>Minimize the given function</p></blockquote></li></ul> | + | <li><blockquote><p>Minimize the given '''function'''</p></blockquote></li></ul> |
− | Note that the '''objective function''' is | + | Note that the '''objective function''' is nonlinear. |
− | The | + | The example has 4 '''variables x1, x2, x3''' and '''x4'''. |
− | There are bounds on the variables, but no constraints otherwise. | + | There are '''bounds''' on the '''variables''', but no constraints otherwise. |
|- | |- | ||
| | | | ||
Line 114: | Line 111: | ||
| I have downloaded the required files to my '''Downloads''' folder. | | I have downloaded the required files to my '''Downloads''' folder. | ||
|- | |- | ||
− | | Open the '''Scilab | + | | Open the '''Scilab''' window >> place the cursor on the '''Scilab console'''. |
| Now open the '''Scilab console.''' | | Now open the '''Scilab console.''' | ||
|- | |- | ||
Line 128: | Line 125: | ||
Video-editor: Pls put a textbox on screen. “In Windows OS ,Click on Open button” | 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'''. | + | Click on the '''Open''' button on the '''toolbar''' and locate the file '''opt_fmincon.sce'''. |
Then click the '''Ok''' button. | Then click the '''Ok''' button. | ||
Line 135: | Line 132: | ||
|- | |- | ||
| Show '''opt_fmincon .sce''' in scilab editor. | | Show '''opt_fmincon .sce''' in scilab editor. | ||
− | | Now we will see the input arguments for '''fot underscore fmincon.''' | + | | Now we will see the '''input arguments''' for '''fot underscore fmincon.''' |
|- | |- | ||
| Highlight '''‘f’''' | | Highlight '''‘f’''' | ||
Line 141: | Line 138: | ||
|- | |- | ||
| Highlight '''‘x0’''' | | Highlight '''‘x0’''' | ||
− | | '''x0''' is a vector with the initial values of the decision variables. | + | | '''x0''' is a '''vector''' with the initial values of the '''decision variables'''. |
|- | |- | ||
| Highlight the line with '''‘A’''' | | Highlight the line with '''‘A’''' | ||
| | | | ||
− | '''''A''''' is a '''matrix''' of '''coefficients''' of | + | '''''A''''' is a '''matrix''' of '''coefficients''' of linear inequality constraints. |
− | + | ||
− | + | ||
|- | |- | ||
| Highlight the line with '''‘b’''' | | Highlight the line with '''‘b’''' | ||
| | | | ||
− | '''''b''''' is a '''vector''' of the right-hand side | + | '''''b''''' is a '''vector''' of the right-hand side of linear inequality constraints. |
− | + | ||
− | of linear | + | |
|- | |- | ||
| Highlight '''‘lb’''' and '''ub''' | | Highlight '''‘lb’''' and '''ub''' | ||
Line 159: | Line 152: | ||
'''lb''' and '''ub''' are the row vectors. | '''lb''' and '''ub''' are the row vectors. | ||
− | They contain the lower and upper bounds of the decision variables respectively. | + | They contain the lower and upper '''bounds''' of the '''decision variables''' respectively. |
|- | |- | ||
| Highlight '''‘Nonlinearcon’''' | | Highlight '''‘Nonlinearcon’''' | ||
| | | | ||
− | '''‘Nonlinearcon’''' is a | + | '''‘Nonlinearcon’''' is a '''Scilab function'''. |
It represents the equality and inequality nonlinear constraints for the problem. | It represents the equality and inequality nonlinear constraints for the problem. | ||
Line 169: | Line 162: | ||
| Highlight Output Arguments | | Highlight Output Arguments | ||
| | | | ||
− | Now we will see the output arguments. | + | Now we will see the '''output arguments'''. |
− | + | '''Output arguments''' are '''xopt, fopt, exitflag, output, lambda, gradient, hessian.''' | |
|- | |- | ||
| Highlight '''‘xopt’''' | | Highlight '''‘xopt’''' | ||
Line 177: | Line 170: | ||
|- | |- | ||
| Highlight '''‘fopt’''' | | Highlight '''‘fopt’''' | ||
− | | '''fopt''' is the optimal | + | | '''fopt''' is the optimal '''objective function''' value. |
|- | |- | ||
| Highlight '''‘exitflag’''' | | Highlight '''‘exitflag’''' | ||
− | | '''exitflag''' is the status of execution | + | | '''exitflag''' is 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’''' | ||
Line 189: | Line 182: | ||
'''Lambda''' is a structure containing the following: | '''Lambda''' is a structure containing the following: | ||
− | '''Lagrange multipliers''' of the lower bounds and upper bounds. | + | '''Lagrange multipliers''' of the lower '''bounds''' and upper '''bounds'''. |
− | Linear equality and inequality constraints at the optimized point. | + | Linear equality and inequality constraints at the '''optimized''' point. |
|- | |- | ||
| Highlight '''‘gradient’''' | | Highlight '''‘gradient’''' | ||
Line 204: | Line 197: | ||
'''[xopt,fopt,exitflag,output, lambda,gradient, hessian] = fot_fmincon(ObjectiveFunction,x0,A,b,[],[],lb,ub,Nonlinearcon)''' | '''[xopt,fopt,exitflag,output, lambda,gradient, hessian] = fot_fmincon(ObjectiveFunction,x0,A,b,[],[],lb,ub,Nonlinearcon)''' | ||
| | | | ||
− | Here we see the ''' | + | Here we see the '''Scilab''' code to define and solve the example. |
We call the '''fot underscore fmincon function''' to solve the given problem. | We call the '''fot underscore fmincon function''' to solve the given problem. | ||
Line 226: | Line 219: | ||
Click Yes to confirm. | Click Yes to confirm. | ||
| | | | ||
− | A confirmation box to clear the Console appears. | + | A confirmation box to clear the '''Console''' appears. |
Click on the '''Yes''' button to confirm. | Click on the '''Yes''' button to confirm. | ||
Line 243: | Line 236: | ||
'''Integer Constraints''' | '''Integer Constraints''' | ||
| | | | ||
− | We will now look at ''' | + | We will now look at constrained '''integer''' nonlinear '''programming''' problems. |
− | These are problems in which some decision variables are constrained to be integers. | + | These are problems in which some '''decision variables''' are constrained to be '''integers'''. |
|- | |- | ||
| | | | ||
Line 251: | Line 244: | ||
'''Mathematical Formulation''' | '''Mathematical Formulation''' | ||
− | | A | + | | A general form of the constrained integer '''optimisation''' problem is as shown. |
|- | |- | ||
| | | | ||
Line 260: | Line 253: | ||
We will now solve this example to illustrate the use of '''fot underscore intfmincon''' | We will now solve this example to illustrate the use of '''fot underscore intfmincon''' | ||
− | In this example, we will demonstrate how to | + | In this example, we will demonstrate how to minimize the given '''function'''. |
− | + | ||
− | + | ||
− | + | ||
− | Note that some of the '''decision variables''' are ''' | + | Note that some of the '''decision variables''' are constrained to be '''integers'''. |
− | Let’s use the previous example with added integer constraints on the | + | 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. | We will use the toolbox to solve this example. | ||
|- | |- | ||
− | | Show '''opt_intfmincon.sce''' in ''' | + | | Show '''opt_intfmincon.sce''' in '''Scilab editor.''' |
| | | | ||
Open the '''Scilab console'''. | Open the '''Scilab console'''. | ||
− | Type editor on the Scilab console and | + | Type editor on the '''Scilab console''' and press '''Enter'''. |
Open '''opt_intfmincon.sce''' in the '''Scilab editor.''' | Open '''opt_intfmincon.sce''' in the '''Scilab editor.''' | ||
Line 281: | Line 271: | ||
| Show opt_intfmincon.sce in scilab editor. | | Show opt_intfmincon.sce in scilab editor. | ||
| | | | ||
− | We have the same input arguments that we had in opt_fmincon.sce. | + | We have the same '''input arguments''' that we had in '''opt_fmincon.sce'''. |
'''f,x0,A,b,lb,ub''' and '''Nonlinearcon''' | '''f,x0,A,b,lb,ub''' and '''Nonlinearcon''' | ||
− | |||
− | Along with them we have an additional input argument called as '''intcon.''' | + | Along with them we have an additional '''input argument''' called as '''intcon.''' |
|- | |- | ||
| Highlight '''‘intcon’''' | | Highlight '''‘intcon’''' | ||
− | | '''intcon''' is a '''vector''' of the '''indices''' of integer variables | + | | '''intcon''' is a '''vector''' of the '''indices''' of '''integer variables'''. |
|- | |- | ||
| Highlight Output Arguments | | Highlight Output Arguments | ||
| | | | ||
− | Now we will see the output arguments. | + | Now we will see the '''output arguments'''. |
− | We have the same output arguments that we had in '''opt_fmincon.sce''' | + | 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)''' | | Highlight '''[xopt,fopt,exitflag,gradient,hessian] = fot_intfmincon(ObjectiveFunction,x0,int,A,b,[],[],lb,ub,Nonlinearcon)''' | ||
Line 340: | Line 329: | ||
<ul> | <ul> | ||
<li><blockquote><p>Use '''fot underscore fmincon''' and '''fot underscore intfmincon''' functions of the '''FOSSEE Optimization Toolbox'''.</p></blockquote></li> | <li><blockquote><p>Use '''fot underscore fmincon''' and '''fot underscore intfmincon''' functions of the '''FOSSEE Optimization Toolbox'''.</p></blockquote></li> | ||
− | <li><blockquote><p>Solve | + | <li><blockquote><p>Solve constrained nonlinear '''programming''' examples in '''Scilab'''.</p></blockquote></li></ul> |
|- | |- | ||
| | | | ||
Line 350: | Line 339: | ||
<ul> | <ul> | ||
− | <li><blockquote><p>Minimise the following objective function subject to the given constraints | + | <li><blockquote><p>Minimise the following '''objective function''' subject to the given constraints</p></blockquote></li> |
− | <li><blockquote><p>The optimal value will be 75728.822 and optimal solution will be | + | <li><blockquote><p>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</p></blockquote></li></ul> |
|- | |- | ||
| | | |
Revision as of 09:25, 16 November 2021
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:
|
Show Slide System Requirements |
To record this tutorial, I am using,
|
Show Slide Pre-requisites |
To follow this tutorial, you should
If not, for relevant tutorials please visit this site. |
Show Slide Code Files |
|
Show Slide What is the Constrained Optimisation problem? |
A constrained nonlinear optimisation problem is a mathematical optimisation model.
It has:
|
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:
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
|
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:
|
Show Slide Assignment |
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: 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. |