This lesson shows how to solve optimization problem created in Toolbox GUI using PSG m-functions.
Step 1. Export problem to Workspace
Firstly, create a problem in the Toolbox. For a quick start, use instructions from Lesson1. Create Problem.
There are two ways to export problem from Toolbox to MATLAB Workspace:
The firs way: use "Save to MAT" in Menu -> Data to C:\Aorda\PSG\MATLAB\Examples\Toolbox\problem_cvar_test.mat.
Load saved in MAT file two MATLAB variables: "toolboxstruc_arr" (structure with data and names of variables) and "problem_statement" (char with Problem Statement):
>> load('C:\Aorda\PSG\MATLAB\Examples\Toolbox\problem_cvar_test.mat');
Create MATLAB variables in Workspace using data and names of variables from "toolboxstruc_arr".
>> psg_export_to_workspace(toolboxstruc_arr);
For more details see tbpsg_export_to_workspace.
The second way: use "Save to Workspace" in Menu -> Data.
This command saves by default two variables to Workspace: "toolboxstruc_arr" (structure with data and names of variables) and "problem_statement" (char with Problem Statement).
Press "Save" button and close "psg_message_screen" window.
Note. Saving to Workspace assumes that all MATLAB variable, used for creation of PSG objects (PSG Matrix, ect), are present in Workspace. So, the command "psg_export_to_workspace" is not needed.
Step 2. Change data in Problem
The following script provides a list of MATLAB variables used in PSG Problem:
>> tbpsg_vars(problem_statement, toolboxstruc_arr)
ans =
MATLAB Object |
PSG Type |
PSG Object |
Location in Problem Statement |
Class |
data1 |
data |
matrix_scenarios |
cvar_risk(0.95, matrix_scenarios) |
double |
point_problem_1_data |
data |
point_problem_1 |
double |
|
point_problem_1_vars |
vars |
point_problem_1 |
cell |
For more details see tbpsg_vars.
MATLAB variable "data1" defines data in PSG Matrix "matrix_scenarios" in function "cvar_risk(0.95, matrix_scenarios)". Change value of this variable (e.g., using "sin" function):
>> data1 = sin([1,2,3;4,5,6]);
Data in "matrix_scenarios" in Toolbox will be changed automatically. To view these changes in Toolbox type in Command window:
>> tbpsg_toolbox(problem_statement, toolboxstruc_arr)
Note. Close Toolbox Window, if it was opened before using this command.
For more details see tbpsg_toolbox.
Solve optimization problem programmatically:
>> [solution_str,outargstruc_arr] = tbpsg_run(problem_statement, toolboxstruc_arr);
All results will be saved to the text report "solution_str" and structure "outargstruc_arr".
For more details, see tbpsg_run.
Solution of the optimization problem in PSG includes Optimal Point, Values of Objective, Constraints, Functions and other information. Toolbox provides an easy way to get needed information from the text report "solution_str" and structure "outargstruc_arr". For example, view objective value (see, tbpsg_objective):
>> [output] = tbpsg_objective(solution_str, outargstruc_arr)
output =
-1.2712e+012
Extract optimal point (see, tbpsg_point_data):
>> [output] = tbpsg_point_data(solution_str, outargstruc_arr)
output =
[1x3 double]
>> output{1}
ans =
1.0e+013 *
1.0000 -0.6304 -1.0000
For more details, see tbpsg_solution.
Step 5. Continue reading Lesson 3