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
[[_ ♕ _ _ _ _ _ _] | |
[_ _ _ _ _ ♕ _ _] | |
[♕ _ _ _ _ _ _ _] | |
[_ _ _ _ _ _ ♕ _] | |
[_ _ _ ♕ _ _ _ _] | |
[_ _ _ _ _ _ _ ♕] | |
[_ _ ♕ _ _ _ _ _] | |
[_ _ _ _ ♕ _ _ _]] |
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
from mosek.fusion import * | |
import numpy as np | |
import sys | |
n = int(sys.argv[1]) | |
M = Model() | |
x = M.variable("x", [n,n], Domain.binary()) | |
M.objective(ObjectiveSense.Maximize, Expr.sum(x)) | |
M.constraint(Expr.sum(x, 0), Domain.lessThan(1)) | |
M.constraint(Expr.sum(x, 1), Domain.lessThan(1)) |
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
from mosek.fusion import * | |
import numpy as np | |
M = Model() | |
x = M.variable(6) | |
groups = [ [0,1,2], [3], [4,5] ] | |
# Some data | |
bounds = [ 1.0, 2.0, 3.0 ] |
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
# Membership matrix | |
Mi = [0, 0, 0, 1, 2, 2] # Rows, Group number for entries of x | |
Mj = [0, 1, 2, 3, 4, 5] # Columns | |
Mv = [1.0] * 6 # Values | |
Memb = Matrix.sparse(3, 6, Mi, Mj, Mv) |
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
# Bounded sums | |
M.constraint( Expr.mul(Memb, x), Domain.lessThan(bounds) ) | |
# Volatility bound | |
M.constraint( Expr.vstack(gamma, | |
Expr.mul(G, Expr.sub( Expr.mul(Memb, x), ind_weights))), | |
Domain.inQCone() ) |
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
z = M.variable(3, Domain.binary()) # Indicates sign for each group | |
bigM = 100 | |
# All items in one group have the same sign | |
zMatch = Expr.mul(Memb.transpose(), z) | |
M.constraint( Expr.sub(x, Expr.mul(bigM, zMatch)), Domain.lessThan(0) ) | |
M.constraint( Expr.sub(Expr.mul(-bigM, Expr.sub(1, zMatch)), x), Domain.lessThan(0) ) |
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
import mosek.fusion.*; | |
c = [ 3.0, 1.0, 5.0, 1.0 ]; | |
A = [ 3.0, 1.0, 2.0, 0.0 ; ... | |
2.0, 1.0, 3.0, 1.0 ; ... | |
0.0, 2.0, 0.0, 3.0 ]; | |
b = [ 2.0, 5.0, 3.0 ]; |
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
x.index(0), x.index(1), x.index(2), x.index(3) |
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
x = M.variable('x', 4, Domain.greaterThan(0.0)); |
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
javaaddpath mosek/9.0/tools/platform/linux64x86/bin/mosek.jar |
NewerOlder