martinbiel / StochasticPrograms.jl

Julia package for formulating and analyzing stochastic recourse models.
MIT License
75 stars 25 forks source link

Normalized coefficient of "decision" variables #9

Closed rtwalker closed 4 years ago

rtwalker commented 4 years ago

I'm running into errors using the normalized_coefficient function on variables that are of type DecisionRef or KnownRef. If the decision variable isn't in the constraint, I'd prefer it to return 0 rather than throwing an error.

Of course I can do some filtering on the front end to avoid calling normalized_coefficient for constraints that aren't AffineDecisonFunctions, but for the sake of convenience/completeness, I wanted to check whether you would be open to a PR adding the following methods?

function JuMP._affine_coefficient(f::_VariableAffExpr{C}, decision::DecisionRef) where C
    return zero(C)
end
function JuMP._affine_coefficient(f::_VariableAffExpr{C}, known::KnownRef) where C
    return zero(C)
end
martinbiel commented 4 years ago

Fine by me! Looking at the JuMP definitions this should probably be the intended behavior anyway.

rtwalker commented 4 years ago

Great! I'll turn it into a PR a little later today