MATPOWER / most

MOST – MATPOWER Optimal Scheduling Tool, for steady-state power systems scheduling problems.
https://matpower.org/
Other
31 stars 12 forks source link

Solver settings when solver set to "DEFAULT" #13

Closed lordleoo closed 5 years ago

lordleoo commented 5 years ago

it is mentioned in MOST manual that if you set most.solver to DEFAULT, MOST will try to look for solvers on your computer, and choose one, with a sequence of priority

if strcmp(alg, 'DEFAULT')
    if have_fcn('gurobi')       %% use Gurobi by default, if available
        alg = 'GUROBI';
    elseif have_fcn('cplex')    %% if not, then CPLEX, if available
        alg = 'CPLEX';
    elseif have_fcn('mosek')    %% if not, then MOSEK, if available
        alg = 'MOSEK';
    elseif isempty(H) || ~any(any(H))   %% if not, and linear objective
        if have_fcn('intlinprog')       %% then Optimization Tbx, if available
            alg = 'OT';
        elseif have_fcn('glpk')         %% if not, and then GLPK, if available
            alg = 'GLPK';
        end
    else
        error('miqps_matpower: no solvers available - requires CPLEX, Gurobi, MOSEK, INTLINPROG or GLPK');
    end
end

if you happened to have anyone of those (GUROBI or CPLEX) on your computer, your choice of DEFAULT will be changed to one of these solvers the program proceeds to fetch the options of these solvers, from mpopt. if you hadn't already sat these options, this will throw the error: "field not found".

For example, inside gurobi_options, at line 94, the program assumes that mpopt.gurobi already exists, and proceeds to check for a field named opt_fname this will throw an error.

The fix would be: inside miqps_matpower and qps_matpower if the program chooses anyone of these priority solvers, it should check if mpopt contains settings for this solver. If not, then some default settings must be set.

another fix which I implemented on my copy of most.m is this if-statement

if (have_fcn('gurobi') || have_fcn('cplex') || have_fcn('mosek') || have_fcn('intlinprog') || have_fcn('glpk')) && ~any(strcmpi(mpopt.most.solver,{'OT'})) && ~any(strcmpi(fieldnames(mpopt),mpopt.most.solver)) %this whole IF statement was added by baraa

%i could easily use isfield instead of strcmpi(fieldnames), but with isfield the name is case-sensitive
warning(['You forgot to set the solver settings: mpopt.',mpopt.most.solver,...
newline,'Proceeding will throw an error. Instead, I will change solver to OT']); %added by baraa
mpopt.most.solver='OT';
end
rdzman commented 5 years ago

Thanks, but can you give me a simple, but full example that demonstrates this problem? I'm not able to reproduce it on my machine. For example, the following (extracted from most_ex6_uc.m) runs just fine for me with no errors, and uses the Gurobi solver ...

mpopt = mpoption('verbose', 2, 'model', 'DC', 'most.solver', 'DEFAULT');
mpc = loadcase('ex_case3b');
xgd = loadxgendata('ex_xgd_uc', mpc);
[iwind, mpc, xgd] = addwind('ex_wind_uc', mpc, xgd);
profiles = getprofiles('ex_wind_profile_d', iwind);
profiles = getprofiles('ex_load_profile', profiles);
nt = size(profiles(1).values, 1);
mdi = loadmd(mpc, nt, xgd, [], [], profiles);
mdo = most(mdi, mpopt);
lordleoo commented 5 years ago

i used to get this error earlier, but now it's not showing. i'm deeply sorry about this let me close it, and i'll get back to it

rdzman commented 5 years ago

No worries. I think this kind of thing could happen if you use mpoption to create an options struct on a setup that doesn't have Gurobi installed, for example, then save that options struct to a MAT file and later load it into an environment that does have Gurobi installed.