/oven2.py Secret
Created
March 3, 2016 13:59
Compact model for the problem in http://yetanothermathprogrammingconsultant.blogspot.dk/2016/02/two-nonlinear-formulations.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def oven2(N, M, A, T): | |
AS = [ 1./math.sqrt(a) for a in A ] | |
with Model() as m: | |
x = m.variable('x', N, Domain.greaterThan(0.) ) | |
y = m.variable('y', N, Domain.inRange(0.,1.0), Domain.isInteger() ) | |
t = m.variable('t', 1, Domain.unbounded() ) | |
m.constraint( Expr.sum(x) , Domain.equalsTo(T) ) | |
m.constraint( Expr.sub( x, Expr.mulElm( M, y) ), Domain.lessThan(0.) ) | |
m.constraint( Expr.vstack( 0.5, t, Expr.mulElm(AS, Expr.sub(A,x)) ), Domain.inRotatedQCone() ) | |
m.objective( ObjectiveSense.Minimize, Expr.sub( t, Expr.dot( A, Expr.sub(1., y ) ) ) ) | |
m.setLogHandler(sys.stdout) | |
m.solve() | |
return x.level(), y.level() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment