/oven1.py Secret
Last active
March 3, 2016 13:39
Fusion implementation of the model at 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 oven1(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() ) | |
s = m.variable('s', n, Domain.unbounded() ) | |
d = m.variable('d', n, Domain.unbounded() ) | |
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.add( s, Expr.mulElm( M, y) ), Domain.lessThan(M) ) | |
m.constraint( Expr.sub( Expr.mulElm( M, y), s ), Domain.lessThan(M) ) | |
m.constraint( Expr.sub( Expr.add(d,x), s), Domain.equalsTo( A) ) | |
m.constraint( Expr.vstack( 0.5, t, Expr.mulElm( d, AS) ), Domain.inRotatedQCone() ) | |
m.objective( ObjectiveSense.Minimize, t) | |
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