jonathancurrie / opti Goto Github PK
View Code? Open in Web Editor NEWOPTI Toolbox
Home Page: https://www.controlengineering.co.nz/Wikis/OPTI/
OPTI Toolbox
Home Page: https://www.controlengineering.co.nz/Wikis/OPTI/
Similar code as my previous issue, but different optimizer: I use filterSD
, which works very well for this particular problem. If it converges, everything is output as expected. But if it hits the time limit, it just ouputs the initial guess as final result, which seems to be a bug.
Consider this example:
% Parameters
substr_0 = 6.21;
substr_in = 3.171;
k_1 = 0.5;
f_1 = 43;
phi_1 = 0.5;
initialVolume = 0;
daysTotal = 7;
hoursTotal = daysTotal*24;
%% Consumer schedule per hour
onOff = [0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 ...
1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 ...
1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0]';
% Initial value: Feeding only during "Consumer ON" time
substr_in_time = substr_in/12.*onOff;
%% Setup optimization problem
parameters = [substr_0, k_1, f_1, phi_1, initialVolume];
% Objective function: Standard deviation of storage volume
objFun = @(feedingVector) substr_Model(feedingVector, onOff, parameters);
% Bounds (lb <= x <= ub), i.e., decision variables can only range between 0 and 6.3
lowerBound = zeros(1, hoursTotal);
upperBound = 2*substr_in.*ones(1, hoursTotal);
% Possible solvers: FilterSD, Ipopt, fmincon (local)
optimOpts = optiset('solver', 'filterSD', 'display', 'iter', 'tolrfun', 1e-2, 'maxiter', 1e5,...
'maxfeval', 1e5*daysTotal, 'maxtime', 90*daysTotal);
Opt = opti('fun', objFun, 'bounds', lowerBound, upperBound, 'x0', substr_in_time,...
'options', optimOpts);
%% Solve optimization problem
tic; [feeding_Opt, fval] = solve(Opt); toc
%% Calculate model with optimal values
substr_Model(feeding_Opt, onOff, parameters)
%% Plot results
figure();
plot(1:hoursTotal, interm1, '-o', 'DisplayName', 'Interm production');
hold on; grid on
stairs(0:hoursTotal-1, 5*onOff, '-', 'DisplayName', 'Consumption schedule');
plot(1:hoursTotal, storageVolume/10, '-^', 'MarkerSize', 4,...
'DisplayName', 'Storage volume [1e-1*m^3]');
stairs(0:hoursTotal-1, feeding_Opt, 'DisplayName', 'Feeding schedule');
xtickVector = 0:12:hoursTotal;
xticks(xtickVector);
xticklabels(xtickVector/24);
xlabel('Time (days)');
legend('Location', 'Best');
set(gca, 'FontSize', 18);
hold off
function storageStd = substr_Model(substr_feeding, onOff, parameters)
hoursTotal = length(substr_feeding);
substr_0 = parameters(1);
k_1 = parameters(2);
f_1 = parameters(3);
phi_1 = parameters(4);
initialVolume = parameters(5);
% Simple for-loop with feeding as vector per hour
substr = zeros(hoursTotal, 1);
substr(1) = (substr_0 + substr_feeding(1))*exp(-k_1/24);
for hour = 2:hoursTotal
substr(hour) = (substr(hour-1) + substr_feeding(hour))*exp(-k_1/24);
end
% Calculate resulting interm1 production and storage volume
interm1 = phi_1*f_1*substr/24;
interm1ConsumptionRate = 11.24509;
storageVolume = initialVolume + cumsum(interm1 - onOff*interm1ConsumptionRate);
assignin('base', 'substr', substr);
assignin('base', 'interm1', interm1);
assignin('base', 'storageVolume', storageVolume);
storageStd = std(storageVolume);
end
Now, set 'maxtime',
to 1*daysTotal
, and it hits time limit after about 600 iterations. But if you do isequal(substr_in_time, feeding_Opt)
, it returns True
, which should not be the case.
Can you reproduce this? How can this be avoided/fixed?
The files in Releases (Which is what I downloaded) are different than master
yet both are version 2.28
. It might cause issues.
I suggest tagging Master as 2.29 and then everything will make sense.
P. S.
I know OPTI is no longer maintained.
Yet it is better be written for others.
Hi, I would like to propose a change to the checkOpti subfunction in buildOpti.m
If the objective function contains an error in execution, checkOpti detects it on line 851.
catch ME
error('OPTI detected an error running a test objective call. Please correct the error below and try again:\n\n%s\n',ME.message);
end
However, the code generates a new exception, and simply prints the string description of the original exception. The problem is that the description does not contain any information about where the original error was generated. For complicated objective functions, it can be difficult to locate which function call or line the original exception belongs to.
Therefore, I propose that checkOpti re-throw the original exception. A standard print or similar can be used to alert the user that OPTI detected an error. Something like:
catch ME
fprintf('\nOPTI detected an error running a test objective call. Please correct the error below and try again:\n\n%s\n\n',ME.message);
rethrow(ME);
end
This way, MATLAB will throw the original exception with all info (including functions and lines with hyperlinks).
hi jonathan
I know that you have included a description for using a multi start solver with opti here : https://www.inverseproblem.co.nz/OPTI/index.php/Advanced/MultiSolve
However, using the option (with MATLAB) returns an error saying the command/function does not exist. I have checked your class definitions and its methods and did find the multisolve() method there. So, my question is, why is it still not working?
I have been using opti for quite sometime with some other solver for nlps (nlopt, nomad, scip and baron). I would very like to test this one out as well and see the difference in the solutions.
Thank you
could you help me with the SCIP Solver? or is it possiable to get a scip.mexw64 file for matlab? Thank you so much
First, I really enjoy OPTI and use it frequently. Very nice package!
Recently, I ran into an issue. It seems that fmincon
gives different results, depending on the calling syntax. Consider this example with OPTI:
% Feeding optimization over time, with algebraic model
% Parameters
substr_0 = 6.21;
substr_in = 3.171;
k_1 = 0.5;
f_1 = 43;
phi_1 = 0.5;
initialVolume = 0;
daysTotal = 7;
hoursTotal = daysTotal*24;
%% Consumer schedule per hour
onOff = [0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 ...
1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 ...
1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 ...
1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0]';
% Initial value: Feeding only during "Consumer ON" time
substr_in_time = substr_in/12.*onOff;
%% Setup optimization problem
parameters = [substr_0, k_1, f_1, phi_1, initialVolume];
% Objective function: Standard deviation of storage volume
objFun = @(feedingVector) substr_Model(feedingVector, onOff, parameters);
% Bounds (lb <= x <= ub), i.e., decision variables can only range between 0 and 6.3
lowerBound = zeros(1, hoursTotal);
upperBound = 2*substr_in.*ones(1, hoursTotal);
% Possible solvers: FilterSD, Ipopt, fmincon (local)
optimOpts = optiset('solver', 'matlab', 'display', 'iter', 'tolrfun', 1e-2, 'maxiter', 1e5,...
'maxfeval', 1e5*daysTotal, 'maxtime', 180*daysTotal);
Opt = opti('fun', objFun, 'bounds', lowerBound, upperBound, 'x0', substr_in_time,...
'options', optimOpts);
%% Solve optimization problem
tic; [feeding_Opt, fval] = solve(Opt); toc
%% Calculate model with optimal values
substr_Model(feeding_Opt, onOff, parameters)
%% Plot results
figure();
plot(1:hoursTotal, interm1, '-o', 'DisplayName', 'Interm production');
hold on; grid on
stairs(0:hoursTotal-1, 5*onOff, '-', 'DisplayName', 'Consumption schedule');
plot(1:hoursTotal, storageVolume/10, '-^', 'MarkerSize', 4,...
'DisplayName', 'Storage volume [1e-1*m^3]');
stairs(0:hoursTotal-1, feeding_Opt, 'DisplayName', 'Feeding schedule');
xtickVector = 0:12:hoursTotal;
xticks(xtickVector);
xticklabels(xtickVector/24);
xlabel('Time (days)');
legend('Location', 'Best');
set(gca, 'FontSize', 18);
hold off
function storageStd = substr_Model(substr_feeding, onOff, parameters)
hoursTotal = length(substr_feeding);
substr_0 = parameters(1);
k_1 = parameters(2);
f_1 = parameters(3);
phi_1 = parameters(4);
initialVolume = parameters(5);
% Simple for-loop with feeding as vector per hour
substr = zeros(hoursTotal, 1);
substr(1) = (substr_0 + substr_feeding(1))*exp(-k_1/24);
for hour = 2:hoursTotal
substr(hour) = (substr(hour-1) + substr_feeding(hour))*exp(-k_1/24);
end
% Calculate resulting interm1 production and storage volume
interm1 = phi_1*f_1*substr/24;
interm1ConsumptionRate = 11.24509;
storageVolume = initialVolume + cumsum(interm1 - onOff*interm1ConsumptionRate);
assignin('base', 'substr', substr);
assignin('base', 'interm1', interm1);
assignin('base', 'storageVolume', storageVolume);
storageStd = std(storageVolume);
end
Objective function value is 15.9630, taking 181 iterations and only 182 function calls.
Now the second one, which calls fmincon
directly (replace lines 30-36):
optimOpts = optimoptions('fmincon', 'Display', 'iter', 'FunctionTolerance', 1e-2,...
'MaxIterations', 1e5, 'MaxFunctionEvaluations', 1e5*daysTotal);
%% Solve optimization problem
tic; [feeding_Opt, fval] = fmincon(objFun, substr_in_time, [], [], [], [],...
lowerBound, upperBound, [], optimOpts); toc
Now, fval = 15.3764, taking 244 iterations and 41419 function calls. So I actually get a better result without OPTI, although it's the same solver under the hood.
Can you reproduce this? What could be the reason? I am on Matlab R2018a btw.
OPTI Toolbox v2.29 installs an old version of SCIP. The latest version of SCIP is v8.1.0: https://scipopt.org/
In addition, as of Nov. 4, 2022, the SCIP license changed to Apache 2.0 License, so that no license is required for commercial use.
I found in the file that IPOPT can directly call ma97 and Pardiso, but I encountered a large-scale optimization problem that these two solvers cannot solve. Therefore, I would like to know how to correctly include ma97 related documents in my HSL related student certificates.
Thank you all!
If I understand correctly, the MEX interface in Ipopt 3.11.x and later removed support for options.auxdata
and moved that functionality into the M-file ipopt_auxdata.m
. I recently discovered that this file is missing from OPTI Toolbox, requiring users who need it to find it and install it separately from the Ipopt source distribution.
Could you please add it to OPTI Toolbox? In the Ipopt source distribution it is found in Ipopt/contrib/MatlabInterface/ipopt_auxdata.m
.
FYI, I am the primary developer of MATPOWER, a power systems analysis and optimization package. MATPOWER includes support for using Ipopt as a solver, and I've been pointing Windows users to OPTI Toolbox as the easiest way to obtain a working Ipopt. And MATPOWER does require the auxdata
support.
Hello, I find an error in the bonmin
solver by using yalmip
and Johan said that is maybe a error in the opti
.
The matlab code is test_if.txt. It is an example of yalmip to model if-else.
OPTI version: v2.28
YALMIP version: '20180817'
Matlab version: r2018a
Error message:
Error using bonmin
*** Error using Bonmin Matlab interface: ***
You have specified a nonexistent BONMIN/IPOPT option
("pardiso_redo_symbolic_fact_only_if_inertia_wrong").
Error in callbonmin (line 126)
[xout,info] = bonmin(model.x0,funcs,options);
Error in solvesdp (line 350)
eval(['output = ' solver.call '(interfacedata);']);
Error in optimize (line 31)
[varargout{1:nargout}] = solvesdp(varargin{:});
Error in test_if (line 34)
optimize(Model,Objective,options)
OPTI Toolbox v2.29 installs NOMAD v3.8.1, but NOMAD v4.3.1 is available. Is it possible to update OPTI Toolbox to use the latest version of NOMAD.
https://www.gerad.ca/en/software/nomad/
When no mex-files are present, it requests the user to download mex files. User input is required, which is not convenient in automated setups.
Please add option to bypass question with predefined answer.
opti_Install
INSTALLING OPTI TOOLBOX ver 2.27
Error in opti_Install (line 38)
matlabVerCheck();
It's nowhere mentioned in the README that it's just for Window.
Any chance that I can also install that under Linux?
And if not it might be very, very nice to tell that the "victim" before he/she embarks on it trying to install it under Linux.
Hi @jonathancurrie. Since this project is no longer supported, can you release all the codes and let community maintain it? I'm interested to make a fork that support mac and linux devices.
As mentioned in this issue #5, you only support windows. Can you share with us the source to build the mex file to support other OS?
Thank you.
Dear Mr. Currie,
I am encountering a problem with the installation of SCIP solver when I install the latest version of OPTI Toolbox v2.28.
As I see, there is a problem when the results of SCIP solver are tested.
I get the message "Reference to non-existent field 'PrimalBound'".
I also tried to run the script opti_SCIP_install.m, but the function opti_GetLibPath() is not found.
I have installed the latest SCIP suite 7.0.1 and I added the path in Matlab. I also added the path of the folders for the OPTI toolbox and the MEX files. Is there any file missing regarding the SCIP solver ?
Thank you very much for your help in advance.
Best regards,
Nikolaos Efkarpidis
When I click the "download" button on the following page:
(https://www.inverseproblem.co.nz/OPTI/index.php/DL/Academic)
I get the message:
Inverse Problem Form Error
Unfortunately you have not completed all the required fields. Please go back to the previous page and complete all fields.
The following fields were not completed or had errors:
ReCaptcha
How can I fix this problem?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.