gseastream / pyomo

The main repository for the Pyomo optimization modeling software.
Other
0 stars 1 forks source link

Fixed variable problem class category #1

Closed qtothec closed 7 years ago

qtothec commented 7 years ago

If I have a nonlinear model in which all of the binary variables are fixed, it should be recognized as NLP rather than MINLP by the writer.

gseastream commented 7 years ago

I changed the writer so that fixed variables are declared as free variables instead of maybe binary or integer, so now GAMS is able to recognize the model as LP or NLP if there are no unfixed MI variables. An additional step can be taken by the user if they include the holdfixed option (in the add_options keyword of the io_options argument to the solver/writer), which tells GAMS to treat fixed variables as constants to reduce the problem size.

qtothec commented 7 years ago

I don't know what @jsiirola will think of the fact that you change the variable domain declaration for fixed variables. Ordinarily, that would raise some concerns with me, but since the GAMS interface isn't designed to be user-readable anyways... idk.

jsiirola commented 7 years ago

Interesting. I would rather the Fixed variables not show up in the model at all. I think that is doable, but will require some additional logic in the to_string logic.

gseastream commented 7 years ago

The following change labels fixed variables and expressions (if expressions show up in constraint bodies) with a string of their fixed values, so they do not show up as variables or expressions in the model at all and are treated exactly like constants:

def var_label(obj):
    if obj.is_fixed():
        return str(value(obj))
    return symbolMap.getSymbol(obj, var_recorder)

Is this the desired behavior?

gseastream commented 7 years ago

@qtothec I just realized something. Since this change now takes fixed variables out of the GAMS model completely (it replaces all occurrences of the variable with its value in the model file), GAMS no longer reports marginals for fixed variables. Is this ok?

Perhaps another thing of note is that since GAMS doesn't report a marginal for a fixed variable, the solver doesn't set a marginal for it either, and if a user tries to access a marginal that doesn't exist then pyomo throws a KeyError.

Just wondering if you were still expecting a marginal to show up for fixed variables.

qtothec commented 7 years ago

That is a fair question. My gut instinct is that the user would still expect to see a marginal for a fixed variable. Does GAMS report a marginal if you implement the fixing via var.FX?

jsiirola commented 7 years ago

FWIW, this behavior is consistent with the rest of Pyomo -- that is, fixed variables are never emitted to the solver, so no marginal is ever computed.

qtothec commented 7 years ago

Well, that works too.

gseastream commented 7 years ago

As a matter of fact GAMS does report marginals for variables fixed via the the var.fx method. But of course that would still require declaring and including the variable in the model, so if the pyomo standard is to leave it the way I made it, then I can do that.

jsiirola commented 7 years ago

My guess is that GAMS computes the marginals as a "service" to the user - and does not rely on the solver (or the solver's presolve) to calculate it for them. I suspect that Pyomo could do the same... BUT, I think that should be the responsibility of the general Pyomo solver API and not be baked into the GAMS solver interface.