├── _config.yml ├── images ├── boxes.png ├── terminal.png └── pointcloud.png ├── third_party ├── .DS_Store └── mosek │ ├── .DS_Store │ └── 9.0 │ └── tools │ ├── platform │ ├── osx64x86 │ │ ├── python │ │ │ ├── 2 │ │ │ │ └── mosek │ │ │ │ │ └── fusion │ │ │ │ │ ├── impl │ │ │ │ │ └── __init__.py │ │ │ │ │ └── Utils.py │ │ │ └── 3 │ │ │ │ └── mosek │ │ │ │ └── fusion │ │ │ │ ├── impl │ │ │ │ └── __init__.py │ │ │ │ └── Utils.py │ │ ├── purepython │ │ │ ├── 2 │ │ │ │ └── mosek │ │ │ │ │ └── fusion │ │ │ │ │ ├── impl │ │ │ │ │ └── __init__.py │ │ │ │ │ └── Utils.py │ │ │ └── 3 │ │ │ │ └── mosek │ │ │ │ └── fusion │ │ │ │ ├── impl │ │ │ │ └── __init__.py │ │ │ │ └── Utils.py │ │ ├── src │ │ │ └── fusion_cxx │ │ │ │ ├── SolverInfo.h │ │ │ │ ├── Debug.cc │ │ │ │ ├── Makefile │ │ │ │ └── IntMap.cc │ │ └── h │ │ │ └── monty_base.h │ ├── linux64x86 │ │ ├── purepython │ │ │ ├── 2 │ │ │ │ └── mosek │ │ │ │ │ └── fusion │ │ │ │ │ ├── impl │ │ │ │ │ └── __init__.py │ │ │ │ │ └── Utils.py │ │ │ └── 3 │ │ │ │ └── mosek │ │ │ │ └── fusion │ │ │ │ ├── impl │ │ │ │ └── __init__.py │ │ │ │ └── Utils.py │ │ ├── python-src │ │ │ ├── 2 │ │ │ │ ├── mosek │ │ │ │ │ └── fusion │ │ │ │ │ │ ├── impl │ │ │ │ │ │ └── __init__.py │ │ │ │ │ │ └── Utils.py │ │ │ │ └── setup.py │ │ │ └── 3 │ │ │ │ ├── mosek │ │ │ │ └── fusion │ │ │ │ │ ├── impl │ │ │ │ │ └── __init__.py │ │ │ │ │ └── Utils.py │ │ │ │ └── setup.py │ │ ├── python │ │ │ ├── 2 │ │ │ │ └── mosek │ │ │ │ │ └── fusion │ │ │ │ │ ├── impl │ │ │ │ │ └── __init__.py │ │ │ │ │ └── Utils.py │ │ │ └── 3 │ │ │ │ └── mosek │ │ │ │ └── fusion │ │ │ │ ├── impl │ │ │ │ └── __init__.py │ │ │ │ └── Utils.py │ │ ├── src │ │ │ └── fusion_cxx │ │ │ │ ├── SolverInfo.h │ │ │ │ ├── Debug.cc │ │ │ │ ├── Makefile │ │ │ │ └── IntMap.cc │ │ └── h │ │ │ └── monty_base.h │ └── .DS_Store │ ├── .DS_Store │ └── examples │ ├── ampl │ ├── ampl1.res │ ├── test.sh │ ├── ampl3.res │ ├── ampl2.res │ └── diet.dat │ ├── data │ ├── feasrepair.lp │ ├── dinfeas.lp │ ├── qo1.mps │ ├── infeas.lp │ ├── sensitivity.ssp │ ├── transport.lp │ ├── lo1.mps │ └── cqo1.mps │ ├── fusion │ ├── python │ │ ├── duality.py │ │ ├── mico1.py │ │ ├── pow1.py │ │ ├── ceo1.py │ │ ├── parameters.py │ │ ├── milo1.py │ │ ├── lo1.py │ │ ├── sdo1.py │ │ ├── mioinitsol.py │ │ ├── breaksolver.py │ │ ├── baker.py │ │ ├── primal_svm.py │ │ ├── total_variation.py │ │ ├── qcqp_sdo_relaxation.py │ │ ├── lpt.py │ │ ├── reoptimization.py │ │ ├── cqo1.py │ │ ├── gp1.py │ │ ├── facility_location.py │ │ └── sudoku.py │ ├── dotnet │ │ ├── duality.cs │ │ ├── mico1.cs │ │ ├── pow1.cs │ │ ├── lo1.cs │ │ ├── mioinitsol.cs │ │ ├── ceo1.cs │ │ ├── milo1.cs │ │ ├── sdo1.cs │ │ ├── parameters.cs │ │ ├── total_variation.cs │ │ ├── primal_svm.cs │ │ └── breaksolver.cs │ ├── java │ │ ├── duality.java │ │ ├── mico1.java │ │ ├── pow1.java │ │ ├── mioinitsol.java │ │ ├── lo1.java │ │ ├── milo1.java │ │ ├── sdo1.java │ │ ├── total_variation.java │ │ ├── ceo1.java │ │ ├── parameters.java │ │ └── breaksolver.java │ └── cxx │ │ ├── mico1.cc │ │ ├── duality.cc │ │ ├── pow1.cc │ │ ├── ceo1.cc │ │ ├── parameters.cc │ │ ├── mioinitsol.cc │ │ ├── lo1.cc │ │ ├── sdo1.cc │ │ ├── milo1.cc │ │ ├── total_variation.cc │ │ ├── primal_svm.cc │ │ └── facility_location.cc │ ├── rmosek │ ├── milo1.R │ ├── qo1.R │ ├── ceo1.R │ ├── simple.R │ ├── mioinitsol.R │ ├── lo1.R │ ├── cqo1.R │ ├── pow1.R │ ├── mico1.R │ ├── parameters.R │ ├── affco2.R │ ├── affco1.R │ ├── portfolio_1_basic.R │ ├── sdo1.R │ └── portfolio_2_frontier.R │ ├── c │ ├── unicode.c │ ├── errorreporting.c │ ├── feasrepairex1.c │ ├── parameters.c │ └── parallel.cc │ ├── java │ ├── opt_server_sync.java │ ├── feasrepairex1.java │ ├── blas_lapack.java │ ├── simple.java │ ├── mico1.java │ └── parameters.java │ ├── python │ ├── opt_server_sync.py │ ├── mico1.py │ ├── feasrepairex1.py │ ├── simple.py │ ├── parameters.py │ ├── parallel.py │ ├── blas_lapack.py │ ├── opt_server_async.py │ └── response.py │ └── dotnet │ ├── opt_server_sync.cs │ ├── feasrepairex1.cs │ ├── simple.cs │ ├── blas_lapack.cs │ ├── mico1.cs │ └── parameters.cs ├── .gitignore ├── src └── bezier_wrapper.cpp └── CMakeLists.txt /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-hacker -------------------------------------------------------------------------------- /images/boxes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OxDuke/Bilevel-Planner/HEAD/images/boxes.png -------------------------------------------------------------------------------- /images/terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OxDuke/Bilevel-Planner/HEAD/images/terminal.png -------------------------------------------------------------------------------- /images/pointcloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OxDuke/Bilevel-Planner/HEAD/images/pointcloud.png -------------------------------------------------------------------------------- /third_party/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OxDuke/Bilevel-Planner/HEAD/third_party/.DS_Store -------------------------------------------------------------------------------- /third_party/mosek/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OxDuke/Bilevel-Planner/HEAD/third_party/mosek/.DS_Store -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/python/2/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/python/3/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/purepython/2/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/purepython/3/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python-src/2/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python-src/3/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python/2/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python/3/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/purepython/2/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/purepython/3/mosek/fusion/impl/__init__.py: -------------------------------------------------------------------------------- 1 | # implementation module directory 2 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OxDuke/Bilevel-Planner/HEAD/third_party/mosek/9.0/tools/.DS_Store -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/ampl/ampl1.res: -------------------------------------------------------------------------------- 1 | model diet.mod; 2 | data diet.dat; 3 | option solver mosek; 4 | solve; 5 | quit; 6 | 7 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/ampl/test.sh: -------------------------------------------------------------------------------- 1 | printf 'AMPL test script' 2 | 3 | mampl < ampl1.res 4 | mampl < ampl2.res 5 | mampl < ampl3.res 6 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OxDuke/Bilevel-Planner/HEAD/third_party/mosek/9.0/tools/platform/.DS_Store -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/ampl/ampl3.res: -------------------------------------------------------------------------------- 1 | model diet.mod; 2 | data diet.dat; 3 | option solver mosek; 4 | option mosek_options 5 | 'msk_ipar_optimizer = msk_optimizer_primal_simplex'; 6 | solve; 7 | display Buy.sstatus; 8 | solve; 9 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/ampl/ampl2.res: -------------------------------------------------------------------------------- 1 | model diet.mod; 2 | data diet.dat; 3 | option solver mosek; 4 | option mosek_options 5 | 'msk_ipar_optimizer=msk_optimizer_primal_simplex \ 6 | msk_ipar_sim_max_iterations=100000'; 7 | solve; 8 | quit; 9 | 10 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/data/feasrepair.lp: -------------------------------------------------------------------------------- 1 | minimize 2 | obj: - 10 x1 - 9 x2 3 | st 4 | c1: + 7e-01 x1 + x2 <= 630 5 | c2: + 5e-01 x1 + 8.333333333e-01 x2 <= 600 6 | c3: + x1 + 6.6666667e-01 x2 <= 708 7 | c4: + 1e-01 x1 + 2.5e-01 x2 <= 135 8 | bounds 9 | x2 >= 650 10 | end 11 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/python/2/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/python/3/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/purepython/2/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/purepython/3/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python-src/2/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python-src/3/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python/2/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python/3/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/purepython/2/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/purepython/3/mosek/fusion/Utils.py: -------------------------------------------------------------------------------- 1 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringIntMap as StringIntMap 2 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_IntMap as IntMap 3 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_StringBuffer as StringBuffer 4 | from mosek.fusion.impl._implementation import mosek_fusion_Utils_Tools as Tools 5 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/data/dinfeas.lp: -------------------------------------------------------------------------------- 1 | maximize + 200 y1 + 1000 y2 + 1000 y3 + 1100 y4 + 200 y5 + 500 y6 + 500 y7 2 | subject to 3 | x11: y1+y4 < 1 4 | x12: y1+y5 < 2 5 | x23: y2+y6 < 5 6 | x24: y2+y7 < 2 7 | x31: y3+y4 < 1 8 | x33: y3+y6 < 2 9 | x34: y3+y7 < 1 10 | bounds 11 | -inf <= y1 < 0 12 | -inf <= y2 < 0 13 | -inf <= y3 < 0 14 | y4 free 15 | y5 free 16 | y6 free 17 | y7 free 18 | end -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/data/qo1.mps: -------------------------------------------------------------------------------- 1 | * File: qo1.mps 2 | NAME qo1 3 | ROWS 4 | N obj 5 | G c1 6 | COLUMNS 7 | x1 c1 1.0 8 | x2 obj -1.0 9 | x2 c1 1.0 10 | x3 c1 1.0 11 | RHS 12 | rhs c1 1.0 13 | QSECTION obj 14 | x1 x1 2.0 15 | x1 x3 -1.0 16 | x2 x2 0.2 17 | x3 x3 2.0 18 | ENDATA -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/data/infeas.lp: -------------------------------------------------------------------------------- 1 | \ 2 | \ An example of an infeasible linear problem. 3 | \ 4 | minimize 5 | obj: + 1 x11 + 2 x12 6 | + 5 x23 + 2 x24 7 | + 1 x31 + 2 x33 + 1 x34 8 | st 9 | s0: + x11 + x12 <= 200 10 | s1: + x23 + x24 <= 1000 11 | s2: + x31 + x33 + x34 <= 1000 12 | d1: + x11 + x31 = 1100 13 | d2: + x12 = 200 14 | d3: + x23 + x33 = 500 15 | d4: + x24 + x34 = 500 16 | bounds 17 | end 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Build Directory 35 | build 36 | bin 37 | 38 | # DS_Store 39 | .DS_Store 40 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/data/sensitivity.ssp: -------------------------------------------------------------------------------- 1 | * Comment 1 2 | 3 | BOUNDS CONSTRAINTS 4 | U "c1" * Analyze upper bound for constraints named c1 5 | U 2 * Analyze upper bound for constraints with index 2 6 | U 3-5 * Analyze upper bound for constraint with index in interval [3:5] 7 | 8 | VARIABLES CONSTRAINTS 9 | L 2-4 * This section specifies which bounds on variables should be analyzed. 10 | L "x11" 11 | OBJECTIVE CONSTRAINTS 12 | "x11" * This section specifies which objective coeficients should be analysed. 13 | 2 -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/data/transport.lp: -------------------------------------------------------------------------------- 1 | minimize 2 | obj: +1 x11 + 2 x12 + 5 x23 + 2 x24 + 1 x31 + 2 x33 + 1 x34 3 | st 4 | c1: + x11 + x12 <= 400 5 | c2: + x23 + x24 <= 1200 6 | c3: + x31 + x33 + x34 <= 1000 7 | c4: + x11 + x31 = 800 8 | c5: + x12 = 100 9 | c6: + x23 + x33 = 500 10 | c7: + x24 + x34 = 500 11 | bounds 12 | end 13 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/data/lo1.mps: -------------------------------------------------------------------------------- 1 | * File: lo1.mps 2 | NAME lo1 3 | OBJSENSE 4 | MAX 5 | ROWS 6 | N obj 7 | E c1 8 | G c2 9 | L c3 10 | COLUMNS 11 | x1 obj 3 12 | x1 c1 3 13 | x1 c2 2 14 | x2 obj 1 15 | x2 c1 1 16 | x2 c2 1 17 | x2 c3 2 18 | x3 obj 5 19 | x3 c1 2 20 | x3 c2 3 21 | x4 obj 1 22 | x4 c2 1 23 | x4 c3 3 24 | RHS 25 | rhs c1 30 26 | rhs c2 15 27 | rhs c3 25 28 | RANGES 29 | BOUNDS 30 | UP bound x2 10 31 | ENDATA -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/data/cqo1.mps: -------------------------------------------------------------------------------- 1 | * File: cqo1.mps 2 | NAME CQO1 EXAMPLE 3 | OBJSENSE 4 | MIN 5 | ROWS 6 | N obj 7 | E c1 8 | COLUMNS 9 | x1 obj 0.0 10 | x1 c1 1.0 11 | x2 obj 0.0 12 | x2 c1 1.0 13 | x3 obj 0.0 14 | x3 c1 2.0 15 | x4 obj 1.0 16 | x5 obj 1.0 17 | x6 obj 1.0 18 | RHS 19 | rhs c1 1.0 20 | BOUNDS 21 | FR bound x4 22 | FR bound x5 23 | FR bound x6 24 | CSECTION k1 0.0 QUAD 25 | x4 26 | x1 27 | x2 28 | CSECTION k2 0.0 RQUAD 29 | x5 30 | x6 31 | x3 32 | ENDATA -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/src/fusion_cxx/SolverInfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | namespace mosek { 6 | namespace fusion { 7 | class SolverInfo 8 | { 9 | private: static std::vector dinfnames; 10 | static std::vector iinfnames; 11 | static std::vector liinfnames; 12 | static MSKdinfiteme dinfsyms[]; 13 | static MSKiinfiteme iinfsyms[]; 14 | static MSKliinfiteme liinfsyms[]; 15 | public: static bool getdouinf( const std::string & infname, MSKdinfiteme & key ); 16 | static bool getintinf( const std::string & infname, MSKiinfiteme & key ); 17 | static bool getlintinf(const std::string & infname, MSKliinfiteme & key ); 18 | }; /* class SolverInfo */ 19 | } /* namespace fusion */ 20 | } /* namespace mosek */ 21 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/src/fusion_cxx/SolverInfo.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | namespace mosek { 6 | namespace fusion { 7 | class SolverInfo 8 | { 9 | private: static std::vector dinfnames; 10 | static std::vector iinfnames; 11 | static std::vector liinfnames; 12 | static MSKdinfiteme dinfsyms[]; 13 | static MSKiinfiteme iinfsyms[]; 14 | static MSKliinfiteme liinfsyms[]; 15 | public: static bool getdouinf( const std::string & infname, MSKdinfiteme & key ); 16 | static bool getintinf( const std::string & infname, MSKiinfiteme & key ); 17 | static bool getlintinf(const std::string & infname, MSKliinfiteme & key ); 18 | }; /* class SolverInfo */ 19 | } /* namespace fusion */ 20 | } /* namespace mosek */ 21 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/duality.py: -------------------------------------------------------------------------------- 1 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 2 | # 3 | # File: duality.py 4 | # 5 | # Purpose: Shows how to access the dual solution 6 | import sys 7 | import mosek 8 | import mosek.fusion 9 | from mosek.fusion import * 10 | 11 | 12 | def main(args): 13 | 14 | A = [[-0.5, 1.0]] 15 | b = [1.0] 16 | c = [1.0, 1.0] 17 | 18 | with Model("duality1") as M: 19 | x = M.variable("x", 2, Domain.greaterThan(0.0)) 20 | 21 | con = M.constraint( 22 | Expr.sub(Expr.mul(Matrix.dense(A), x), b), Domain.equalsTo(0.0)) 23 | 24 | M.objective("obj", ObjectiveSense.Minimize, Expr.dot(c, x)) 25 | M.solve() 26 | 27 | print("x =", x.level()) 28 | print("s =", x.dual()) 29 | print("y =", con.dual()) 30 | 31 | if __name__ == '__main__': 32 | main(sys.argv[1:]) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/mico1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: mico1.py 5 | # 6 | # Purpose: Demonstrates how to solve a small mixed 7 | # integer conic optimization problem. 8 | # 9 | # minimize x^2 + y^2 10 | # subject to x >= e^y + 3.8 11 | # x, y - integer 12 | ## 13 | 14 | import sys 15 | from mosek.fusion import * 16 | 17 | with Model('mico1') as M: 18 | 19 | x = M.variable(Domain.integral(Domain.unbounded())) 20 | y = M.variable(Domain.integral(Domain.unbounded())) 21 | t = M.variable() 22 | 23 | M.constraint(Expr.vstack(t, x, y), Domain.inQCone()) 24 | M.constraint(Expr.vstack(Expr.sub(x, 3.8), 1, y), Domain.inPExpCone()) 25 | 26 | M.objective(ObjectiveSense.Minimize, t) 27 | 28 | M.setLogHandler(sys.stdout) 29 | M.solve() 30 | 31 | print('Solution: x = {0}, y = {1}'.format(x.level()[0], y.level()[0])) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/milo1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : milo1.R 5 | # 6 | # Purpose : To demonstrate how to solve a small mixed integer linear 7 | # optimization problem using the Rmosek package. 8 | ## 9 | library("Rmosek") 10 | 11 | milo1 <- function() 12 | { 13 | # Specify the continuous part of the problem. 14 | prob <- list(sense="max") 15 | prob$c <- c(1, 0.64) 16 | prob$A <- Matrix(rbind(c(50, 31), 17 | c( 3, -2)), sparse=TRUE) 18 | prob$bc <- rbind(blc=c(-Inf, -4), 19 | buc=c( 250, Inf)) 20 | prob$bx <- rbind(blx=c( 0, 0), 21 | bux=c(Inf, Inf)) 22 | 23 | # Specify the integer constraints 24 | prob$intsub <- c(1 ,2) 25 | 26 | # Solve the problem 27 | r <- mosek(prob) 28 | 29 | # Return the solution 30 | stopifnot(identical(r$response$code, 0)) 31 | r$sol 32 | } 33 | 34 | milo1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/qo1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : qo1.R 5 | # 6 | # Purpose : To demonstrate how to solve a small quadratic 7 | # optimization problem using the Rmosek package. 8 | ## 9 | library("Rmosek") 10 | 11 | qo1 <- function() 12 | { 13 | # Specify the non-quadratic part of the problem. 14 | prob <- list(sense="min") 15 | prob$c <- c(0, -1, 0) 16 | prob$A <- Matrix(c(1, 1, 1), nrow=1, sparse=TRUE) 17 | prob$bc <- rbind(blc=1, 18 | buc=Inf) 19 | prob$bx <- rbind(blx=rep(0,3), 20 | bux=rep(Inf,3)) 21 | 22 | # Specify the quadratic objective matrix in triplet form. 23 | prob$qobj$i <- c(1, 3, 2, 3) 24 | prob$qobj$j <- c(1, 1, 2, 3) 25 | prob$qobj$v <- c(2, -1, 0.2, 2) 26 | 27 | # Solve the problem 28 | r <- mosek(prob) 29 | 30 | # Return the solution 31 | stopifnot(identical(r$response$code, 0)) 32 | r$sol 33 | } 34 | 35 | qo1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/ceo1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : ceo1.R 5 | # 6 | # Purpose : To demonstrate how to solve a small conic exponential 7 | # optimization problem using the Rmosek package. 8 | ## 9 | library("Rmosek") 10 | 11 | ceo1 <- function() 12 | { 13 | # Specify the non-conic part of the problem. 14 | prob <- list(sense="min") 15 | prob$c <- c(1, 1, 0) 16 | prob$A <- Matrix(c(1, 1, 1), nrow=1, sparse=TRUE) 17 | prob$bc <- rbind(blc=1, 18 | buc=1) 19 | prob$bx <- rbind(blx=rep(-Inf,3), 20 | bux=rep( Inf,3)) 21 | 22 | # Specify the cones. 23 | NUMCONES <- 1 24 | prob$cones <- matrix(list(), nrow=2, ncol=NUMCONES) 25 | rownames(prob$cones) <- c("type","sub") 26 | 27 | prob$cones[,1] <- list("PEXP", c(1, 2, 3)) 28 | 29 | # Solve the problem 30 | r <- mosek(prob) 31 | 32 | # Return the solution 33 | stopifnot(identical(r$response$code, 0)) 34 | r$sol 35 | } 36 | 37 | ceo1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/simple.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : simple.R 5 | # 6 | # Purpose : To demonstrate a very simple example using the Rmosek package 7 | # to read a problem file, solve the optimization problem and 8 | # write the solution. 9 | ## 10 | library("Rmosek") 11 | 12 | simple <- function(filename) 13 | { 14 | # Read problem 15 | r <- mosek_read(filename, list(verbose=1, usesol=FALSE, useparam=TRUE)) 16 | stopifnot(identical(r$response$code, 0)) 17 | prob <- r$prob 18 | 19 | # Solve problem 20 | r <- mosek(prob, list(verbose=1)) 21 | stopifnot(identical(r$response$code, 0)) 22 | sol <- r$sol 23 | 24 | # Print solution 25 | print(sol) 26 | } 27 | 28 | # Run only if called directly from the command-line 29 | if( sys.nframe() == 0L ) 30 | { 31 | args <- commandArgs(trailingOnly=TRUE) 32 | if( !file.exists(args[1]) ) { 33 | stop("Expected problem file as input argument.") 34 | } 35 | 36 | simple(args[1]) 37 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/duality.cs: -------------------------------------------------------------------------------- 1 | /* 2 | File : duality.cs 3 | 4 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 5 | 6 | Description : Shows how to read the dual value of a constraint 7 | */ 8 | using System; 9 | using mosek.fusion; 10 | 11 | namespace mosek.fusion.example 12 | { 13 | public class duality 14 | { 15 | public static void Main(string[] args) 16 | { 17 | double[,] A = new double[,] { { -0.5, 1.0 } }; 18 | double[] b = new double[] { 1.0 }; 19 | double[] c = new double[] { 1.0, 1.0 }; 20 | 21 | using (Model M = new Model("duality")) 22 | { 23 | Variable x = M.Variable("x", 2, Domain.GreaterThan(0.0)); 24 | 25 | Constraint con = M.Constraint(Expr.Sub(b, Expr.Mul(Matrix.Dense(A), x)), Domain.EqualsTo(0.0)); 26 | 27 | M.Objective("obj", ObjectiveSense.Minimize, Expr.Dot(c, x)); 28 | 29 | M.Solve(); 30 | double[] xsol = x.Level(); 31 | double[] ysol = con.Dual(); 32 | 33 | Console.WriteLine("x1,x2,y = %{0}, %{1}, %{2}\n", xsol[0], xsol[1], ysol[0]); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/duality.java: -------------------------------------------------------------------------------- 1 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 2 | // 3 | // File: duality.java 4 | // 5 | // Purpose: Show how to read the dual value of a constraint. 6 | package com.mosek.fusion.examples; 7 | import mosek.fusion.*; 8 | 9 | public class duality { 10 | public static void main(String[] args) 11 | throws SolutionError { 12 | double[][] A = { { -0.5, 1.0 } }; 13 | double[] b = { 1.0 }; 14 | double[] c = { 1.0, 1.0 }; 15 | 16 | Model M = new Model("duality"); 17 | try { 18 | Variable x = M.variable("x", 2, Domain.greaterThan(0.0)); 19 | 20 | Constraint con = M.constraint(Expr.sub(Expr.mul(Matrix.dense(A), x), b), Domain.equalsTo(0.0)); 21 | 22 | M.objective("obj", ObjectiveSense.Minimize, Expr.dot(c, x)); 23 | 24 | M.solve(); 25 | double[] xsol = x.level(); 26 | double[] ssol = x.dual(); 27 | double[] ysol = con.dual(); 28 | 29 | System.out.printf("x1,x2,s1,s2,y = %e, %e, %e, %e, %e\n", xsol[0], xsol[1], ssol[0], ssol[1], ysol[0]); 30 | } finally { 31 | M.dispose(); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/pow1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: pow1.py 5 | # 6 | # Purpose: Demonstrates how to solve the problem 7 | # 8 | # maximize x^0.2*y^0.8 + z^0.4 - x 9 | # st x + y + 0.5z = 2 10 | # x,y,z >= 0 11 | # 12 | ## 13 | 14 | from mosek.fusion import * 15 | 16 | with Model('pow1') as M: 17 | 18 | x = M.variable('x', 3, Domain.unbounded()) 19 | x3 = M.variable() 20 | x4 = M.variable() 21 | 22 | # Create the linear constraint 23 | M.constraint(Expr.dot(x, [1.0, 1.0, 0.5]), Domain.equalsTo(2.0)) 24 | 25 | # Create the power cone constraints 26 | M.constraint(Var.vstack(x.slice(0,2), x3), Domain.inPPowerCone(0.2)) 27 | M.constraint(Expr.vstack(x.index(2), 1.0, x4), Domain.inPPowerCone(0.4)) 28 | 29 | # Set the objective function 30 | M.objective(ObjectiveSense.Maximize, Expr.dot([1.0,1.0,-1.0], Var.vstack(x3, x4, x.index(0)))) 31 | 32 | # Solve the problem 33 | M.solve() 34 | 35 | # Get the linear solution values 36 | solx = x.level() 37 | print('x,y,z = %s' % str(solx)) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/mioinitsol.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : mioinitsol.R 5 | # 6 | # Purpose : To demonstrate how to solve a linear mixed-integer 7 | # problem with a start guess. 8 | ## 9 | library("Rmosek") 10 | 11 | mioinitsol <- function() 12 | { 13 | # Specify the problem. 14 | prob <- list(sense="max") 15 | prob$c <- c(7, 10, 1, 5) 16 | prob$A <- Matrix(c(1, 1, 1, 1), nrow=1, sparse=TRUE) 17 | prob$bc <- rbind(blc=-Inf, 18 | buc=2.5) 19 | prob$bx <- rbind(blx=rep(0,4), 20 | bux=rep(Inf,4)) 21 | prob$intsub <- c(1 ,2, 3) 22 | 23 | # Specify start guess for the integer variables. 24 | prob$sol$int$xx <- c(1, 1, 0, NaN) 25 | 26 | # Solve the problem 27 | r <- mosek(prob, list(getinfo=TRUE)) 28 | 29 | # The solution 30 | stopifnot(identical(r$response$code, 0)) 31 | print(r$sol$int$xx) 32 | 33 | # Was the initial solution used ? 34 | print(r$iinfo$MIO_CONSTRUCT_SOLUTION) 35 | print(r$dinfo$MIO_CONSTRUCT_SOLUTION_OBJ) 36 | } 37 | 38 | mioinitsol() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/mico1.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: mico1.cs 5 | // 6 | // Purpose: Demonstrates how to solve a small mixed 7 | // integer conic optimization problem. 8 | // 9 | // minimize x^2 + y^2 10 | // subject to x >= e^y + 3.8 11 | // x, y - integer 12 | // 13 | using System; 14 | using mosek.fusion; 15 | 16 | namespace mosek.fusion.example 17 | { 18 | public class mico1 19 | { 20 | public static void Main(string[] args) 21 | { 22 | using (Model M = new Model("mico1")) 23 | { 24 | Variable x = M.Variable(Domain.Integral(Domain.Unbounded())); 25 | Variable y = M.Variable(Domain.Integral(Domain.Unbounded())); 26 | Variable t = M.Variable(); 27 | 28 | M.Constraint(Expr.Vstack(t, x, y), Domain.InQCone()); 29 | M.Constraint(Expr.Vstack(Expr.Sub(x, 3.8), 1, y), Domain.InPExpCone()); 30 | 31 | M.Objective(ObjectiveSense.Minimize, t); 32 | 33 | M.Solve(); 34 | 35 | Console.WriteLine("x, y = {0}, {1}", x.Level()[0], y.Level()[0]); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/lo1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : lo1.R 5 | # 6 | # Purpose : To demonstrate how to solve a small linear 7 | # optimization problem using the Rmosek package. 8 | ## 9 | library("Rmosek") 10 | 11 | lo1 <- function() 12 | { 13 | prob <- list() 14 | 15 | # Objective sense (maximize or minimize) 16 | prob$sense <- "max" 17 | 18 | # Objective coefficients 19 | prob$c <- c(3, 1, 5, 1) 20 | 21 | # Specify matrix 'A' in sparse format. 22 | asubi <- c(1, 1, 1, 2, 2, 2, 2, 3, 3) 23 | asubj <- c(1, 2, 3, 1, 2, 3, 4, 2, 4) 24 | aval <- c(3, 1, 2, 2, 1, 3, 1, 2, 3) 25 | 26 | prob$A <- sparseMatrix(asubi,asubj,x=aval) 27 | 28 | # Bound values for constraints 29 | prob$bc <- rbind(blc=c(30, 15, -Inf), 30 | buc=c(30, Inf, 25)) 31 | 32 | # Bound values for variables 33 | prob$bx <- rbind(blx=rep(0,4), 34 | bux=c(Inf, 10, Inf, Inf)) 35 | 36 | # Solve the problem 37 | r <- mosek(prob) 38 | 39 | # Return the solution 40 | stopifnot(identical(r$response$code, 0)) 41 | r$sol 42 | } 43 | 44 | lo1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/src/fusion_cxx/Debug.cc: -------------------------------------------------------------------------------- 1 | #include "fusion_p.h" 2 | #include 3 | #include "monty.h" 4 | 5 | //#include "mosektask_p.h" 6 | 7 | namespace mosek 8 | { 9 | namespace fusion 10 | { 11 | Debug::Debug() : ptr(new p_Debug(this)) {} 12 | Debug::t Debug::o() { return new Debug(); } 13 | Debug::t Debug::p(const std::string & val) { return ptr->p(val); } 14 | Debug::t Debug::p( int val) { return ptr->p(val); } 15 | Debug::t Debug::p(long long val) { return ptr->p(val); } 16 | Debug::t Debug::p(double val) { return ptr->p(val); } 17 | Debug::t Debug::p( bool val) { return ptr->p(val); } 18 | Debug::t Debug::p(const std::shared_ptr> & val) { return ptr->p(val); } 19 | Debug::t Debug::p(const std::shared_ptr> & val) { return ptr->p(val); } 20 | Debug::t Debug::p(const std::shared_ptr> & val) { return ptr->p(val); } 21 | Debug::t Debug::lf() { return ptr->lf(); } 22 | 23 | Debug::~Debug() { delete ptr; ptr = NULL; } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/c/unicode.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: unicode.c 5 | 6 | Purpose: To demonstrate how to use unicoded strings. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "mosek.h" 14 | 15 | int main(int argc, const char *argv[]) 16 | { 17 | char output[512]; 18 | wchar_t *input = L"My task name"; 19 | MSKenv_t env; 20 | MSKrescodee r; 21 | MSKtask_t task; 22 | size_t len, conv; 23 | 24 | r = MSK_makeenv(&env, NULL); 25 | 26 | if (r == MSK_RES_OK) 27 | { 28 | r = MSK_makeemptytask(env, &task); 29 | 30 | if (r == MSK_RES_OK) 31 | { 32 | /* 33 | The wchar_t string input specifying the task name 34 | is converted to a UTF8 string that can be inputted 35 | to MOSEK. 36 | */ 37 | r = MSK_wchartoutf8(sizeof(output), &len, &conv, output, input); 38 | 39 | if (r == MSK_RES_OK) 40 | r = MSK_puttaskname(task, output); 41 | 42 | MSK_deletetask(&task); 43 | } 44 | 45 | MSK_deleteenv(&env); 46 | } 47 | 48 | printf("Return code - %d\n", r); 49 | return (r); 50 | } /* main */ -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/src/fusion_cxx/Debug.cc: -------------------------------------------------------------------------------- 1 | #include "fusion_p.h" 2 | #include 3 | #include "monty.h" 4 | 5 | //#include "mosektask_p.h" 6 | 7 | namespace mosek 8 | { 9 | namespace fusion 10 | { 11 | Debug::Debug() : ptr(new p_Debug(this)) {} 12 | Debug::t Debug::o() { return new Debug(); } 13 | Debug::t Debug::p(const std::string & val) { return ptr->p(val); } 14 | Debug::t Debug::p( int val) { return ptr->p(val); } 15 | Debug::t Debug::p(long long val) { return ptr->p(val); } 16 | Debug::t Debug::p(double val) { return ptr->p(val); } 17 | Debug::t Debug::p( bool val) { return ptr->p(val); } 18 | Debug::t Debug::p(const std::shared_ptr> & val) { return ptr->p(val); } 19 | Debug::t Debug::p(const std::shared_ptr> & val) { return ptr->p(val); } 20 | Debug::t Debug::p(const std::shared_ptr> & val) { return ptr->p(val); } 21 | Debug::t Debug::lf() { return ptr->lf(); } 22 | 23 | Debug::~Debug() { delete ptr; ptr = NULL; } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/mico1.java: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: mico1.java 5 | // 6 | // Purpose: Demonstrates how to solve a small mixed 7 | // integer conic optimization problem. 8 | // 9 | // minimize x^2 + y^2 10 | // subject to x >= e^y + 3.8 11 | // x, y - integer 12 | // 13 | package com.mosek.fusion.examples; 14 | import mosek.fusion.*; 15 | 16 | public class mico1 { 17 | public static void main(String[] args) 18 | throws SolutionError { 19 | 20 | Model M = new Model("mico1"); 21 | 22 | try { 23 | Variable x = M.variable(Domain.integral(Domain.unbounded())); 24 | Variable y = M.variable(Domain.integral(Domain.unbounded())); 25 | Variable t = M.variable(); 26 | 27 | M.constraint(Expr.vstack(t, x, y), Domain.inQCone()); 28 | M.constraint(Expr.vstack(Expr.sub(x, 3.8), 1, y), Domain.inPExpCone()); 29 | 30 | M.objective(ObjectiveSense.Minimize, t); 31 | 32 | M.solve(); 33 | 34 | System.out.printf("x, y = %f, %f\n", x.level()[0], y.level()[0]); 35 | 36 | } finally { 37 | M.dispose(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/java/opt_server_sync.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : opt_server_sync.java 5 | 6 | Purpose : Demonstrates how to use MOSEK OptServer 7 | to solve optimization problem synchronously 8 | 9 | */ 10 | package com.mosek.example; 11 | import mosek.*; 12 | 13 | public class opt_server_sync { 14 | public static void main (String[] args) { 15 | if (args.length == 0) { 16 | System.out.println ("Missing argument, syntax is:"); 17 | System.out.println (" opt_server_sync inputfile host port numpolls"); 18 | } else { 19 | 20 | String inputfile = args[0]; 21 | String host = args[1]; 22 | String port = args[2]; 23 | 24 | rescode trm[] = new rescode[1]; 25 | 26 | try (Env env = new Env(); 27 | Task task = new Task(env, 0, 0)) { 28 | task.set_Stream (mosek.streamtype.log, 29 | new mosek.Stream() { 30 | public void stream(String msg) { System.out.print(msg); } 31 | }); 32 | 33 | task.readdata (inputfile); 34 | 35 | task.optimizermt (host, port, trm); 36 | 37 | task.solutionsummary (mosek.streamtype.log); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/mico1.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: mico1.cc 5 | // 6 | // Purpose: Demonstrates how to solve a small mixed 7 | // integer conic optimization problem. 8 | // 9 | // minimize x^2 + y^2 10 | // subject to x >= e^y + 3.8 11 | // x, y - integer 12 | // 13 | #include 14 | #include 15 | #include "fusion.h" 16 | 17 | using namespace mosek::fusion; 18 | using namespace monty; 19 | 20 | int main(int argc, char ** argv) 21 | { 22 | Model::t M = new Model("mico1"); auto _M = finally([&]() { M->dispose(); }); 23 | 24 | Variable::t x = M->variable(Domain::integral(Domain::unbounded())); 25 | Variable::t y = M->variable(Domain::integral(Domain::unbounded())); 26 | Variable::t t = M->variable(); 27 | 28 | M->constraint(Expr::vstack(t, x, y), Domain::inQCone()); 29 | M->constraint(Expr::vstack(Expr::sub(x, 3.8), 1, y), Domain::inPExpCone()); 30 | 31 | M->objective(ObjectiveSense::Minimize, t); 32 | 33 | M->solve(); 34 | 35 | std::cout << std::setprecision(2) 36 | << "x = " << (*(x->level()))[0] << std::endl 37 | << "y = " << (*(y->level()))[0] << std::endl ; 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/ceo1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: ceo1.py 5 | # 6 | # Purpose: Demonstrates how to solve the problem 7 | # 8 | # minimize x1 + x2 9 | # such that 10 | # x1 + x2 + x3 = 1.0 11 | # x1,x2 >= 0.0 12 | # and x1 >= x2 * exp(x3/x2) 13 | ## 14 | 15 | from mosek.fusion import * 16 | 17 | with Model('ceo1') as M: 18 | 19 | x = M.variable('x', 3, Domain.unbounded()) 20 | 21 | # Create the constraint 22 | # x[0] + x[1] + x[2] = 1.0 23 | M.constraint("lc", Expr.sum(x), Domain.equalsTo(1.0)) 24 | 25 | # Create the conic exponential constraint 26 | expc = M.constraint("expc", x, Domain.inPExpCone()) 27 | 28 | # Set the objective function to (x[0] + x[1]) 29 | M.objective("obj", ObjectiveSense.Minimize, Expr.sum(x.slice(0,2))) 30 | 31 | # Solve the problem 32 | M.solve() 33 | 34 | M.writeTask('ceo1.ptf') 35 | # Get the linear solution values 36 | solx = x.level() 37 | print('x1,x2,x3 = %s' % str(solx)) 38 | 39 | # Get conic solution of expc 40 | expcval = expc.level() 41 | expcdual = expc.dual() 42 | print('expc levels = %s' % str(expcval)) 43 | print('expc dual conic var levels = %s' % str(expcdual)) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/cqo1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : cqo1.R 5 | # 6 | # Purpose : To demonstrate how to solve a small conic quadratic 7 | # optimization problem using the Rmosek package. 8 | ## 9 | library("Rmosek") 10 | 11 | cqo1 <- function() 12 | { 13 | # Specify the non-conic part of the problem. 14 | prob <- list(sense="min") 15 | prob$c <- c(0, 0, 0, 1, 1, 1) 16 | prob$A <- Matrix(c(1, 1, 2, 0, 0, 0), nrow=1, sparse=TRUE) 17 | prob$bc <- rbind(blc=1, 18 | buc=1) 19 | prob$bx <- rbind(blx=c(rep(0,3), rep(-Inf,3)), 20 | bux=rep(Inf,6)) 21 | 22 | # Specify the cones. 23 | NUMCONES <- 2 24 | prob$cones <- matrix(list(), nrow=2, ncol=NUMCONES) 25 | rownames(prob$cones) <- c("type","sub") 26 | 27 | prob$cones[,1] <- list("QUAD", c(4, 1, 2)) 28 | prob$cones[,2] <- list("RQUAD", c(5, 6, 3)) 29 | 30 | # 31 | # Use cbind to extend this chunk of cones if needed: 32 | # 33 | # oldcones <- prob$cones 34 | # prob$cones <- cbind(oldcones, newcones) 35 | # 36 | 37 | # Solve the problem 38 | r <- mosek(prob) 39 | 40 | # Return the solution 41 | stopifnot(identical(r$response$code, 0)) 42 | r$sol 43 | } 44 | 45 | cqo1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/pow1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : pow1.R 5 | # 6 | # Purpose : To demonstrate how to solve a small power cone 7 | # optimization problem using the Rmosek package. 8 | ## 9 | library("Rmosek") 10 | 11 | pow1 <- function() 12 | { 13 | # Specify the non-conic part of the problem. 14 | prob <- list(sense="max") 15 | prob$c <- c(-1, 0, 0, 1, 1, 0) 16 | prob$A <- Matrix(c(1, 1, 0.5, 0, 0, 0), nrow=1, sparse=TRUE) 17 | prob$bc <- rbind(blc=2, 18 | buc=2) 19 | prob$bx <- rbind(blx=c(rep(-Inf,5), 1), 20 | bux=c(rep( Inf,5), 1)) 21 | 22 | # Specify the cones. 23 | NUMCONES <- 2 24 | prob$cones <- matrix(list(), nrow=3, ncol=NUMCONES) 25 | rownames(prob$cones) <- c("type","sub","conepar") 26 | 27 | prob$cones[,1] <- list("PPOW", c(1, 2, 4), c(0.2, 0.8)) 28 | prob$cones[,2] <- list("PPOW", c(3, 6, 5), c(0.4, 0.6)) 29 | 30 | # 31 | # Non-parametric cones (such as "QUAD") are ignorant to the existence of 32 | # the third row "conepar" and can be assigned any value (such as NaN). 33 | # 34 | 35 | # Solve the problem 36 | r <- mosek(prob) 37 | 38 | # Return the solution 39 | stopifnot(identical(r$response$code, 0)) 40 | r$sol 41 | } 42 | 43 | pow1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/duality.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: duality.cc 5 | // 6 | // Purpose: A small example of how to access dual values. 7 | 8 | #include 9 | #include 10 | #include 11 | #include "fusion.h" 12 | 13 | using namespace mosek::fusion; 14 | using namespace monty; 15 | 16 | int main(int argc, char ** argv) 17 | { 18 | auto A = new_array_ptr({ { -0.5, 1.0 } }); 19 | auto b = new_array_ptr({ 1.0 }); 20 | auto c = new_array_ptr({ 1.0, 1.0 }); 21 | 22 | Model::t M = new Model("duality"); auto _M = finally([&]() { M->dispose(); }); 23 | 24 | Variable::t x = M->variable("x", 2, Domain::greaterThan(0.0)); 25 | 26 | Constraint::t con = M->constraint(Expr::sub(Expr::mul(A, x), b), Domain::equalsTo(0.0)); 27 | 28 | M->objective("obj", ObjectiveSense::Minimize, Expr::dot(c, x)); 29 | 30 | M->solve(); 31 | auto xsol = x->level(); 32 | auto ssol = x->dual(); 33 | auto ysol = con->dual(); 34 | 35 | std::cout << std::setiosflags(std::ios::scientific) 36 | << "x1 = " << (*xsol)[0] << std::endl 37 | << "x2 = " << (*xsol)[1] << std::endl 38 | << "s1 = " << (*ssol)[0] << std::endl 39 | << "s1 = " << (*ssol)[1] << std::endl 40 | << "y = " << (*ysol)[0] << std::endl; 41 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/mico1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : mico1.R 5 | # 6 | # Purpose : To demonstrate how to solve a small mixed integer conic 7 | # optimization problem using the Rmosek package. 8 | # 9 | # minimize x^2 + y^2 10 | # subject to x >= e^y + 3.8 11 | # x, y - integer 12 | ## 13 | library("Rmosek") 14 | 15 | mico1 <- function() 16 | { 17 | # Specify the continuous part of the problem. 18 | # Variables are [t; x; y] 19 | prob <- list(sense="min") 20 | prob$c <- c(1, 0, 0) 21 | prob$A <- Matrix(nrow=0, ncol=3) # 0 constraints, 3 variables 22 | prob$bx <- rbind(blx=rep(-Inf,3), bux=rep(Inf,3)) 23 | 24 | # Conic part of the problem 25 | prob$F <- rbind(diag(3), c(0,1,0), c(0,0,0), c(0,0,1)) 26 | prob$g <- c(0, 0, 0, -3.8, 1, 0) 27 | prob$cones <- cbind(matrix(list("QUAD", 3, NULL), nrow=3, ncol=1), 28 | matrix(list("PEXP", 3, NULL), nrow=3, ncol=1)) 29 | rownames(prob$cones) <- c("type","dim","conepar") 30 | 31 | # Specify the integer constraints 32 | prob$intsub <- c(2 ,3) 33 | 34 | # Solve the problem 35 | r <- mosek(prob) 36 | 37 | # Return the solution 38 | stopifnot(identical(r$response$code, 0)) 39 | print(r$sol$int$xx[2:3]) 40 | } 41 | 42 | mico1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/opt_server_sync.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : opt_server_sync.py 5 | # 6 | # Purpose : Demonstrates how to use MOSEK OptServer 7 | # to solve optimization problem asynchronously 8 | ## 9 | import mosek 10 | import sys 11 | 12 | def streamprinter(msg): 13 | sys.stdout.write(msg) 14 | sys.stdout.flush() 15 | 16 | if len(sys.argv) <= 3: 17 | print("Missing argument, syntax is:") 18 | print(" opt_server_sync inputfile host port") 19 | else: 20 | 21 | inputfile = sys.argv[1] 22 | host = sys.argv[2] 23 | port = sys.argv[3] 24 | 25 | # Create the mosek environment. 26 | with mosek.Env() as env: 27 | 28 | # Create a task object linked with the environment env. 29 | # We create it with 0 variables and 0 constraints initially, 30 | # since we do not know the size of the problem. 31 | with env.Task(0, 0) as task: 32 | task.set_Stream(mosek.streamtype.log, streamprinter) 33 | 34 | # We assume that a problem file was given as the first command 35 | # line argument (received in `argv') 36 | task.readdata(inputfile) 37 | 38 | # Solve the problem remotely 39 | task.optimizermt(host, port) 40 | 41 | # Print a summary of the solution 42 | task.solutionsummary(mosek.streamtype.log) -------------------------------------------------------------------------------- /src/bezier_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * bazier_wrapper.cpp 3 | * Copyright (C) 2018 Gao Tang 4 | * 5 | * Distributed under terms of the MIT license. 6 | */ 7 | 8 | 9 | // A wrapper for the C++ Bezier code to be used in Python for 10 | 11 | #include "pybind11/eigen.h" 12 | #include "pybind11/stl.h" 13 | #include "pybind11/stl_bind.h" 14 | #include "ott/bezier_base.h" 15 | 16 | 17 | class pyBezier: public Bernstein{ 18 | public: 19 | pyBezier() : Bernstein(){} 20 | pyBezier(int poly_order_min, int poly_order_max, double min_order) : Bernstein(poly_order_min, poly_order_max, min_order){ 21 | } 22 | }; 23 | 24 | 25 | namespace py = pybind11; 26 | PYBIND11_MODULE(libbezier, m){ 27 | py::class_(m, "Bezier") 28 | .def(py::init<>()) 29 | .def(py::init()) 30 | .def("M", &pyBezier::getM) 31 | .def("MQM", &pyBezier::getMQM) 32 | .def("FM", &pyBezier::getFM) 33 | .def("C", &pyBezier::getC) 34 | .def("C_v", &pyBezier::getC_v) 35 | .def("C_a", &pyBezier::getC_a) 36 | .def("C_j", &pyBezier::getC_j) 37 | .def("A_v", &pyBezier::getA_v) 38 | .def("A_a", &pyBezier::getA_a) 39 | .def("A_j", &pyBezier::getA_j) 40 | .def("order_min", &pyBezier::order_min) 41 | .def("min_order", &pyBezier::min_order) 42 | .def("order_max", &pyBezier::order_max) 43 | .def("print_M", &pyBezier::printM) 44 | ; 45 | } 46 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/dotnet/opt_server_sync.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: opt_server_sync.cs 5 | 6 | Purpose : Demonstrates how to use MOSEK OptServer 7 | to solve optimization problem synchronously 8 | */ 9 | using System; 10 | 11 | namespace mosek.example 12 | { 13 | class msgclass : mosek.Stream 14 | { 15 | public override void streamCB (string msg) 16 | { 17 | Console.Write ("{0}", msg); 18 | } 19 | } 20 | 21 | public class simple 22 | { 23 | public static void Main (string[] args) 24 | { 25 | if (args.Length == 0) 26 | { 27 | Console.WriteLine ("Missing arguments, syntax is:"); 28 | Console.WriteLine (" opt_server_sync inputfile host port"); 29 | } 30 | else 31 | { 32 | String inputfile = args[0]; 33 | String host = args[1]; 34 | String port = args[2]; 35 | 36 | mosek.rescode trm; 37 | 38 | using (mosek.Env env = new mosek.Env()) 39 | { 40 | using (mosek.Task task = new mosek.Task(env)) 41 | { 42 | task.set_Stream (mosek.streamtype.log, new msgclass ()); 43 | 44 | task.readdata (inputfile); 45 | 46 | task.optimizermt (host, port, out trm); 47 | 48 | task.solutionsummary (mosek.streamtype.log); 49 | } 50 | } 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/java/feasrepairex1.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : feasrepairex1.java 5 | 6 | Purpose : To demonstrate how to use the MSK_relaxprimal function to 7 | locate the cause of an infeasibility. 8 | 9 | Syntax : On command line 10 | 11 | java feasrepairex1.feasrepairex1 feasrepair.lp 12 | 13 | feasrepair.lp is located in mosek\\tools\examples. 14 | */ 15 | package com.mosek.example; 16 | 17 | import mosek.*; 18 | 19 | public class feasrepairex1 { 20 | 21 | public static void main (String[] args) { 22 | String filename = "../data/feasrepair.lp"; 23 | if (args.length >= 1) filename = args[0]; 24 | 25 | try (Env env = new Env(); 26 | Task task = new Task(env, 0, 0)) { 27 | task.set_Stream( 28 | mosek.streamtype.log, 29 | new mosek.Stream() 30 | { public void stream(String msg) { System.out.print(msg); }}); 31 | 32 | task.readdata(filename); 33 | 34 | task.putintparam(mosek.iparam.log_feas_repair, 3); 35 | 36 | task.primalrepair(null, null, null, null); 37 | 38 | double sum_viol = task.getdouinf(mosek.dinfitem.primal_repair_penalty_obj); 39 | 40 | System.out.println("Minimized sum of violations = " + sum_viol); 41 | 42 | task.optimize(); 43 | 44 | task.solutionsummary(mosek.streamtype.msg); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/pow1.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: pow1.cc 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // maximize x^0.2*y^0.8 + z^0.4 - x 9 | // st x + y + 0.5z = 2 10 | // x,y,z >= 0 11 | // 12 | #include 13 | #include "fusion.h" 14 | 15 | using namespace mosek::fusion; 16 | using namespace monty; 17 | 18 | int main(int argc, char ** argv) 19 | { 20 | Model::t M = new Model("pow1"); auto _M = finally([&]() { M->dispose(); }); 21 | 22 | Variable::t x = M->variable("x", 3, Domain::unbounded()); 23 | Variable::t x3 = M->variable(); 24 | Variable::t x4 = M->variable(); 25 | 26 | // Create the linear constraint 27 | auto aval = new_array_ptr({1.0, 1.0, 0.5}); 28 | M->constraint(Expr::dot(x, aval), Domain::equalsTo(2.0)); 29 | 30 | // Create the conic constraints 31 | M->constraint(Var::vstack(x->slice(0,2), x3), Domain::inPPowerCone(0.2)); 32 | M->constraint(Expr::vstack(x->index(2), 1.0, x4), Domain::inPPowerCone(0.4)); 33 | 34 | auto cval = new_array_ptr({1.0, 1.0, -1.0}); 35 | M->objective(ObjectiveSense::Maximize, Expr::dot(cval, Var::vstack(x3, x4, x->index(0)))); 36 | 37 | // Solve the problem 38 | M->solve(); 39 | 40 | // Get the linear solution values 41 | ndarray xlvl = *(x->level()); 42 | std::cout << "x,y,z = " << xlvl << std::endl; 43 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/src/fusion_cxx/Makefile: -------------------------------------------------------------------------------- 1 | MSKMAJORVER=9 2 | MSKMINORVER=0 3 | CXX=g++ -std=c++11 4 | LD=g++ -std=c++11 5 | AR=ar 6 | 7 | CFLAGS_DEBUG=-g 8 | CFLAGS_RELEASE=-O2 9 | 10 | CFLAGS=-O2 -fPIC 11 | IPATHS=-I../../h -I. 12 | 13 | libfusion64.so.$(MSKMAJORVER).$(MSKMINORVER): fusion.os BaseModel.os Debug.os mosektask.os IntMap.os SolverInfo.os StringBuffer.os 14 | $(LD) -shared -L../../bin -Wl,-rpath-link,../../bin '-Wl,-rpath,$$ORIGIN' -o libfusion64.so.$(MSKMAJORVER).$(MSKMINORVER) fusion.os mosektask.os BaseModel.os Debug.os IntMap.os SolverInfo.os StringBuffer.os -lmosek64 15 | 16 | libfusion64.a: fusion.os BaseModel.os Debug.os mosektask.os IntMap.os SolverInfo.os StringBuffer.os 17 | $(AR) r libfusion64.a fusion.os BaseModel.os Debug.os mosektask.os IntMap.os SolverInfo.os StringBuffer.os 18 | 19 | %.os: %.cc 20 | $(CXX) $(IPATHS) $(CFLAGS) -c -o $@ $< 21 | 22 | .PHONY: clean install 23 | 24 | install: ../../bin/libfusion64.so.$(MSKMAJORVER).$(MSKMINORVER) ../../bin/libfusion64.so 25 | 26 | ../../bin/libfusion64.so.$(MSKMAJORVER).$(MSKMINORVER): libfusion64.so.$(MSKMAJORVER).$(MSKMINORVER) libfusion64.a 27 | install libfusion64.so.$(MSKMAJORVER).$(MSKMINORVER) ../../bin 28 | install libfusion64.a ../../bin 29 | ../../bin/libfusion64.so: ../../bin/libfusion64.so.$(MSKMAJORVER).$(MSKMINORVER) 30 | rm -f ../../bin/libfusion64.so && ln -s ./libfusion64.so.$(MSKMAJORVER).$(MSKMINORVER) ../../bin/libfusion64.so 31 | 32 | clean: 33 | rm -rf *.os 34 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python-src/3/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup,Extension 2 | from distutils.command.install import INSTALL_SCHEMES 3 | import distutils.cmd 4 | import platform,sys,shutil 5 | import os,os.path 6 | import subprocess 7 | import ctypes 8 | 9 | 10 | 11 | major,minor,_,_,_ = sys.version_info 12 | if major != 3 or minor < 3: 13 | print("Python 3.3+ required, got %d.%d" % (major,minor)) 14 | sys.exit(1) 15 | 16 | setup( name = 'Mosek', 17 | version = '$(version)', 18 | description = 'Mosek/Python APIs', 19 | long_description = 'Interface for MOSEK', 20 | author = 'Mosek ApS', 21 | author_email = "support@mosek.com", 22 | license = "See license.pdf in the MOSEK distribution", 23 | url = 'http://www.mosek.com', 24 | packages = [ 'mosek', 'mosek.fusion','mosek.fusion.impl' ], 25 | ext_modules = [ Extension('mosek._msk', 26 | include_dirs = ["src/",'../../h'], 27 | libraries = ['mosek64'], 28 | library_dirs = ['../../bin'], 29 | sources = ['src/_msk.c']), 30 | Extension('mosek.fusion.impl.fragments', 31 | sources = ['src/mosek-py.c', 32 | 'src/Tools.c']) ]) 33 | 34 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/python-src/2/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup,Extension 2 | from distutils.command.install import INSTALL_SCHEMES 3 | import distutils.cmd 4 | import platform,sys,shutil 5 | import os,os.path 6 | import subprocess 7 | import ctypes 8 | 9 | 10 | 11 | major,minor,_,_,_ = sys.version_info 12 | if major != 2 or minor < 5: 13 | print("Python 2.5+ required, got %d.%d" % (major,minor)) 14 | sys.exit(1) 15 | 16 | setup( name = 'Mosek', 17 | version = '$(version)', 18 | description = 'Mosek/Python APIs', 19 | long_description = 'Interface for MOSEK', 20 | author = 'Mosek ApS', 21 | author_email = "support@mosek.com", 22 | license = "See license.pdf in the MOSEK distribution", 23 | url = 'http://www.mosek.com', 24 | packages = [ 'mosek', 'mosek.fusion','mosek.fusion.impl' ], 25 | ext_modules = [ Extension('mosek._msk', 26 | include_dirs = ["src/",'../../h'], 27 | libraries = ['mosek64'], 28 | library_dirs = ['../../bin'], 29 | sources = ['src/_msk.c']), 30 | Extension('mosek.fusion.impl.fragments', 31 | sources = ['src/mosek-py.c', 32 | 'src/Tools.c' ]) ] ) 33 | 34 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/parameters.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : parameters.py 5 | # 6 | # Purpose : Demonstrates a very simple example about how to set 7 | # parameters and read information items 8 | # with MOSEK Fusion 9 | ## 10 | from mosek.fusion import * 11 | 12 | # Create the Model 13 | with Model() as M: 14 | print('Test MOSEK parameter get/set functions') 15 | 16 | # Set log level (integer parameter) 17 | M.setSolverParam("log", 1) 18 | # Select interior-point optimizer... (parameter with symbolic string values) 19 | M.setSolverParam("optimizer", "intpnt") 20 | # ... without basis identification (parameter with symbolic string values) 21 | M.setSolverParam("intpntBasis", "never") 22 | # Set relative gap tolerance (double parameter) 23 | M.setSolverParam("intpntCoTolRelGap", 1.0e-7) 24 | 25 | # The same in a different way 26 | M.setSolverParam("intpntCoTolRelGap", "1.0e-7") 27 | 28 | # Incorrect value 29 | try: 30 | M.setSolverParam("intpntCoTolRelGap", -1) 31 | except ParameterError as e: 32 | print('Wrong parameter value') 33 | 34 | 35 | # Define and solve an optimization problem here 36 | # M.solve() 37 | # After optimization: 38 | 39 | print('Get MOSEK information items') 40 | 41 | tm = M.getSolverDoubleInfo("optimizerTime") 42 | it = M.getSolverIntInfo("intpntIter") 43 | 44 | print('Time: {0}\nIterations: {1}'.format(tm,it)) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/pow1.java: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: pow1.java 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // maximize x^0.2*y^0.8 + z^0.4 - x 9 | // st x + y + 0.5z = 2 10 | // x,y,z >= 0 11 | // 12 | 13 | package com.mosek.fusion.examples; 14 | import mosek.fusion.*; 15 | 16 | public class pow1 { 17 | public static void main(String[] args) 18 | throws SolutionError { 19 | Model M = new Model("pow1"); 20 | try { 21 | Variable x = M.variable("x", 3, Domain.unbounded()); 22 | Variable x3 = M.variable(); 23 | Variable x4 = M.variable(); 24 | 25 | // Create the linear constraint 26 | double[] aval = new double[] {1.0, 1.0, 0.5}; 27 | M.constraint(Expr.dot(x, aval), Domain.equalsTo(2.0)); 28 | 29 | // Create the conic constraints 30 | M.constraint(Var.vstack(x.slice(0,2), x3), Domain.inPPowerCone(0.2)); 31 | M.constraint(Expr.vstack(x.index(2), 1.0, x4), Domain.inPPowerCone(0.4)); 32 | 33 | // Set the objective function 34 | double[] cval = new double[] {1.0, 1.0, -1.0}; 35 | M.objective(ObjectiveSense.Maximize, Expr.dot(cval, Var.vstack(x3, x4, x.index(0)))); 36 | 37 | // Solve the problem 38 | M.solve(); 39 | 40 | // Get the linear solution values 41 | double[] solx = x.level(); 42 | System.out.printf("x, y, z = %e, %e, %e\n", solx[0], solx[1], solx[2]); 43 | } finally { 44 | M.dispose(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/ceo1.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: ceo1.cc 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // minimize x1 + x2 9 | // such that 10 | // x1 + x2 + x3 = 1.0 11 | // x1,x2 >= 0.0 12 | // and x1 >= x2 * exp(x3/x2) 13 | // 14 | #include 15 | #include "fusion.h" 16 | 17 | using namespace mosek::fusion; 18 | using namespace monty; 19 | 20 | int main(int argc, char ** argv) 21 | { 22 | Model::t M = new Model("ceo1"); auto _M = finally([&]() { M->dispose(); }); 23 | 24 | Variable::t x = M->variable("x", 3, Domain::unbounded()); 25 | 26 | // Create the constraint 27 | // x[0] + x[1] + x[2] = 1.0 28 | M->constraint("lc", Expr::sum(x), Domain::equalsTo(1.0)); 29 | 30 | // Create the exponential conic constraint 31 | Constraint::t expc = M->constraint("expc", x, Domain::inPExpCone()); 32 | 33 | // Set the objective function to (x[0] + x[1]) 34 | M->objective("obj", ObjectiveSense::Minimize, Expr::sum(x->slice(0,2))); 35 | 36 | // Solve the problem 37 | M->solve(); 38 | 39 | // Get the linear solution values 40 | ndarray xlvl = *(x->level()); 41 | // Get conic solution of expc1 42 | ndarray expclvl = *(expc->level()); 43 | ndarray expcdl = *(expc->dual()); 44 | 45 | std::cout << "x1,x2,x3 = " << xlvl << std::endl; 46 | std::cout << "expc levels = " << expclvl << std::endl; 47 | std::cout << "expc dual conic var levels = " << expcdl << std::endl; 48 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/dotnet/feasrepairex1.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: feasrepairex1.cs 5 | 6 | Purpose: To demonstrate how to use the MSK_relaxprimal function to 7 | locate the cause of an infeasibility. 8 | 9 | Syntax: On command line 10 | feasrepairex1 feasrepair.lp 11 | feasrepair.lp is located in mosek\\tools\examples. 12 | */ 13 | using System; 14 | 15 | namespace mosek.example 16 | { 17 | class msgclass : mosek.Stream 18 | { 19 | public msgclass () {} 20 | 21 | public override void streamCB (string msg) 22 | { 23 | Console.Write ("{1}", msg); 24 | } 25 | } 26 | 27 | public class feasrepairex1 28 | { 29 | public static void Main (String[] args) 30 | { 31 | string filename = "../data/feasrepair.lp"; 32 | if (args.Length >= 1) filename = args[0]; 33 | 34 | using (mosek.Env env = new mosek.Env()) 35 | { 36 | using (mosek.Task task = new mosek.Task(env, 0, 0)) 37 | { 38 | task.set_Stream (mosek.streamtype.log, new msgclass()); 39 | 40 | task.readdata(filename); 41 | 42 | task.putintparam(mosek.iparam.log_feas_repair, 3); 43 | 44 | task.primalrepair(null, null, null, null); 45 | 46 | double sum_viol = task.getdouinf(mosek.dinfitem.primal_repair_penalty_obj); 47 | 48 | Console.WriteLine("Minimized sum of violations = %{0}", sum_viol); 49 | 50 | task.optimize(); 51 | task.solutionsummary(mosek.streamtype.msg); 52 | } 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/milo1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: milo1.py 5 | # 6 | # Purpose: Demonstrates how to solve a small mixed 7 | # integer linear optimization problem. 8 | ## 9 | 10 | import sys 11 | from mosek.fusion import * 12 | 13 | def main(args): 14 | A = [[50.0, 31.0], 15 | [3.0, -2.0]] 16 | c = [1.0, 0.64] 17 | 18 | with Model('milo1') as M: 19 | 20 | x = M.variable('x', 2, Domain.integral(Domain.greaterThan(0.0))) 21 | 22 | # Create the constraints 23 | # 50.0 x[0] + 31.0 x[1] <= 250.0 24 | # 3.0 x[0] - 2.0 x[1] >= -4.0 25 | M.constraint('c1', Expr.dot(A[0], x), Domain.lessThan(250.0)) 26 | M.constraint('c2', Expr.dot(A[1], x), Domain.greaterThan(-4.0)) 27 | 28 | # Set max solution time 29 | M.setSolverParam('mioMaxTime', 60.0) 30 | # Set max relative gap (to its default value) 31 | M.setSolverParam('mioTolRelGap', 1e-4) 32 | # Set max absolute gap (to its default value) 33 | M.setSolverParam('mioTolAbsGap', 0.0) 34 | 35 | # Set the objective function to (c^T * x) 36 | M.objective('obj', ObjectiveSense.Maximize, Expr.dot(c, x)) 37 | 38 | # Solve the problem 39 | M.solve() 40 | 41 | # Get the solution values 42 | print('[x0, x1] = ', x.level()) 43 | print("MIP rel gap = %.2f (%f)" % (M.getSolverDoubleInfo( 44 | "mioObjRelGap"), M.getSolverDoubleInfo("mioObjAbsGap"))) 45 | 46 | if __name__ == '__main__': 47 | main(sys.argv[1:]) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/lo1.py: -------------------------------------------------------------------------------- 1 | #### 2 | ## Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | ## 4 | ## File: lo1.py 5 | ## 6 | ## Purpose: Demonstrates how to solve the problem 7 | ## 8 | ## maximize 3*x0 + 1*x1 + 5*x2 + x3 9 | ## such that 10 | ## 3*x0 + 1*x1 + 2*x2 = 30, 11 | ## 2*x0 + 1*x1 + 3*x2 + 1*x3 > 15, 12 | ## 2*x1 + + 3*x3 < 25 13 | ## and 14 | ## x0,x1,x2,x3 > 0, 15 | ## 0 < x1 < 10 16 | #### 17 | 18 | import sys 19 | from mosek.fusion import * 20 | 21 | def main(args): 22 | A = [[3.0, 1.0, 2.0, 0.0], 23 | [2.0, 1.0, 3.0, 1.0], 24 | [0.0, 2.0, 0.0, 3.0]] 25 | c = [3.0, 1.0, 5.0, 1.0] 26 | 27 | # Create a model with the name 'lo1' 28 | with Model("lo1") as M: 29 | 30 | # Create variable 'x' of length 4 31 | x = M.variable("x", 4, Domain.greaterThan(0.0)) 32 | 33 | # Create constraints 34 | M.constraint(x.index(1), Domain.lessThan(10.0)) 35 | M.constraint("c1", Expr.dot(A[0], x), Domain.equalsTo(30.0)) 36 | M.constraint("c2", Expr.dot(A[1], x), Domain.greaterThan(15.0)) 37 | M.constraint("c3", Expr.dot(A[2], x), Domain.lessThan(25.0)) 38 | 39 | # Set the objective function to (c^t * x) 40 | M.objective("obj", ObjectiveSense.Maximize, Expr.dot(c, x)) 41 | 42 | # Solve the problem 43 | M.solve() 44 | 45 | # Get the solution values 46 | sol = x.level() 47 | print('\n'.join(["x[%d] = %f" % (i, sol[i]) for i in range(4)])) 48 | 49 | if __name__ == '__main__': 50 | main(sys.argv[1:]) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/parameters.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : parameters.R 5 | # 6 | # Purpose : To demonstrate how to set parameters 7 | # using the Rmosek package. 8 | ## 9 | library("Rmosek") 10 | 11 | parameters <- function() 12 | { 13 | # Specify the optimization problem 14 | prob <- list(sense="max") 15 | prob$c <- c(3, 1, 5, 1) 16 | prob$A <- sparseMatrix(i=c(1, 1, 1, 2, 2, 2, 2, 3, 3), 17 | j=c(1, 2, 3, 1, 2, 3, 4, 2, 4), 18 | x=c(3, 1, 2, 2, 1, 3, 1, 2, 3)) 19 | prob$bc <- rbind(blc=c(30, 15, -Inf), 20 | buc=c(30, Inf, 25)) 21 | prob$bx <- rbind(blx=rep(0,4), 22 | bux=c(Inf, 10, Inf, Inf)) 23 | 24 | # Specify the parameters 25 | 26 | # Set log level (integer parameter) 27 | # and select interior-point optimizer... (integer parameter) 28 | # ... without basis identification (integer parameter) 29 | prob$iparam <- list(LOG=0, OPTIMIZER="OPTIMIZER_INTPNT", INTPNT_BASIS="BI_NEVER") 30 | 31 | # Set relative gap tolerance (double parameter) 32 | prob$dparam <- list(INTPNT_CO_TOL_REL_GAP=1.0e-7) 33 | 34 | # Solve the problem 35 | r <- mosek(prob) 36 | 37 | # Demonstrate retrieving information items 38 | 39 | opts <- list(getinfo=TRUE) 40 | r <- mosek(prob, opts) 41 | 42 | print(r$dinfo$OPTIMIZER_TIME) 43 | print(r$iinfo$INTPNT_ITER) 44 | 45 | # Return the solution 46 | stopifnot(identical(r$response$code, 0)) 47 | r$sol 48 | } 49 | 50 | parameters() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/pow1.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: pow1.cs 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // maximize x^0.2*y^0.8 + z^0.4 - x 9 | // st x + y + 0.5z = 2 10 | // x,y,z >= 0 11 | // 12 | using System; 13 | using mosek.fusion; 14 | 15 | namespace mosek.fusion.example 16 | { 17 | public class pow1 18 | { 19 | public static void Main(string[] args) 20 | { 21 | using (Model M = new Model("pow1")) 22 | { 23 | 24 | Variable x = M.Variable("x", 3, Domain.Unbounded()); 25 | Variable x3 = M.Variable(); 26 | Variable x4 = M.Variable(); 27 | 28 | // Create the linear constraint 29 | double[] aval = new double[] {1.0, 1.0, 0.5}; 30 | M.Constraint(Expr.Dot(x, aval), Domain.EqualsTo(2.0)); 31 | 32 | // Create the exponential conic constraint 33 | // Create the conic constraints 34 | M.Constraint(Var.Vstack(x.Slice(0,2), x3), Domain.InPPowerCone(0.2)); 35 | M.Constraint(Expr.Vstack(x.Index(2), 1.0, x4), Domain.InPPowerCone(0.4)); 36 | 37 | // Set the objective function 38 | double[] cval = new double[] {1.0, 1.0, -1.0}; 39 | M.Objective(ObjectiveSense.Maximize, Expr.Dot(cval, Var.Vstack(x3, x4, x.Index(0)))); 40 | 41 | // Solve the problem 42 | M.Solve(); 43 | 44 | // Get the linear solution values 45 | double[] solx = x.Level(); 46 | Console.WriteLine("x,y,z = {0}, {1}, {2}", solx[0], solx[1], solx[2]); 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/src/fusion_cxx/Makefile: -------------------------------------------------------------------------------- 1 | MSKMAJORVER=9 2 | MSKMINORVER=0 3 | CXX=clang++ -std=c++11 4 | LD=clang++ -std=c++11 5 | AR=ar 6 | 7 | CFLAGS=-O2 -fPIC 8 | IPATHS=-I../../h -I. 9 | 10 | libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib: fusion.os BaseModel.os Debug.os mosektask.os IntMap.os SolverInfo.os StringBuffer.os 11 | $(LD) -headerpad_max_install_names -shared -L../../bin -o libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib fusion.os BaseModel.os Debug.os mosektask.os IntMap.os SolverInfo.os StringBuffer.os -lmosek64 12 | install_name_tool -change libmosek64.$(MSKMAJORVER).$(MSKMINORVER).dylib $(shell cd ../../bin; pwd)/libmosek64.$(MSKMAJORVER).$(MSKMINORVER).dylib libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib 13 | 14 | libfusion64.a: fusion.os BaseModel.os Debug.os mosektask.os IntMap.os SolverInfo.os StringBuffer.os 15 | $(AR) r libfusion64.a fusion.os BaseModel.os Debug.os mosektask.os IntMap.os SolverInfo.os StringBuffer.os 16 | 17 | %.os: %.cc 18 | $(CXX) $(IPATHS) $(CFLAGS) -c -o $@ $< 19 | 20 | .PHONY: clean install 21 | 22 | install: ../../bin/libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib ../../bin/libfusion64.dylib 23 | 24 | ../../bin/libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib: libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib libfusion64.a 25 | install libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib ../../bin 26 | install libfusion64.a ../../bin 27 | 28 | ../../bin/libfusion64.dylib: ../../bin/libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib 29 | rm -f ../../bin/libfusion64.dylib && ln -s ./libfusion64.$(MSKMAJORVER).$(MSKMINORVER).dylib ../../bin/libfusion64.dylib 30 | 31 | clean: 32 | rm -rf *.os 33 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/sdo1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: sdo1.py 5 | # 6 | # Purpose: 7 | # Solves the mixed semidefinite and conic quadratic optimization problem 8 | # 9 | # [2, 1, 0] 10 | # minimize Tr [1, 2, 1] * X + x0 11 | # [0, 1, 2] 12 | # 13 | # [1, 0, 0] 14 | # subject to Tr [0, 1, 0] * X + x0 = 1.0 15 | # [0, 0, 1] 16 | # 17 | # [1, 1, 1] 18 | # Tr [1, 1, 1] * X + x1 + x2 = 0.5 19 | # [1, 1, 1] 20 | # 21 | # X >> 0, x0 >= (x1^2 + x2^2) ^ (1/2) 22 | ## 23 | 24 | import sys 25 | import mosek 26 | from mosek.fusion import * 27 | 28 | def main(args): 29 | with Model("sdo1") as M: 30 | 31 | # Setting up the variables 32 | X = M.variable("X", Domain.inPSDCone(3)) 33 | x = M.variable("x", Domain.inQCone(3)) 34 | 35 | # Setting up constant coefficient matrices 36 | C = Matrix.dense ( [[2.,1.,0.],[1.,2.,1.],[0.,1.,2.]] ) 37 | A1 = Matrix.eye(3) 38 | A2 = Matrix.ones(3,3) 39 | 40 | # Objective 41 | M.objective(ObjectiveSense.Minimize, Expr.add(Expr.dot(C, X), x.index(0))) 42 | 43 | # Constraints 44 | M.constraint("c1", Expr.add(Expr.dot(A1, X), x.index(0)), Domain.equalsTo(1.0)) 45 | M.constraint("c2", Expr.add(Expr.dot(A2, X), Expr.sum(x.slice(1,3))), Domain.equalsTo(0.5)) 46 | 47 | M.solve() 48 | 49 | print(X.level()) 50 | print(x.level()) 51 | 52 | if __name__ == '__main__': 53 | main(sys.argv[1:]) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/h/monty_base.h: -------------------------------------------------------------------------------- 1 | #ifndef _MONTY_BASE_H_ 2 | #define _MONTY_BASE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace monty 8 | { 9 | template struct _integer_type { }; 10 | template<> struct _integer_type { typedef long long int t; }; 11 | template<> struct _integer_type { typedef unsigned long long int t; }; 12 | template<> struct _integer_type { typedef int t; }; 13 | template<> struct _integer_type { typedef unsigned int t; }; 14 | template<> struct _integer_type { typedef short int t; }; 15 | template<> struct _integer_type { typedef unsigned short int t; }; 16 | template<> struct _integer_type { typedef signed char t; }; 17 | template<> struct _integer_type { typedef unsigned char t; }; 18 | 19 | 20 | template 21 | struct const_iterable_t 22 | { 23 | typedef Iterable t; 24 | typedef typename t::const_iterator const_iterator; 25 | Iterable itable; 26 | 27 | const_iterable_t(const Iterable & itable) : itable(itable) { } 28 | const_iterator begin() { return itable.begin(); } 29 | const_iterator end() { return itable.end(); } 30 | }; 31 | 32 | template 33 | const_iterable_t iterable(const T & itable) 34 | { 35 | return const_iterable_t(itable); 36 | } 37 | 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/h/monty_base.h: -------------------------------------------------------------------------------- 1 | #ifndef _MONTY_BASE_H_ 2 | #define _MONTY_BASE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace monty 8 | { 9 | template struct _integer_type { }; 10 | template<> struct _integer_type { typedef long long int t; }; 11 | template<> struct _integer_type { typedef unsigned long long int t; }; 12 | template<> struct _integer_type { typedef int t; }; 13 | template<> struct _integer_type { typedef unsigned int t; }; 14 | template<> struct _integer_type { typedef short int t; }; 15 | template<> struct _integer_type { typedef unsigned short int t; }; 16 | template<> struct _integer_type { typedef signed char t; }; 17 | template<> struct _integer_type { typedef unsigned char t; }; 18 | 19 | 20 | template 21 | struct const_iterable_t 22 | { 23 | typedef Iterable t; 24 | typedef typename t::const_iterator const_iterator; 25 | Iterable itable; 26 | 27 | const_iterable_t(const Iterable & itable) : itable(itable) { } 28 | const_iterator begin() { return itable.begin(); } 29 | const_iterator end() { return itable.end(); } 30 | }; 31 | 32 | template 33 | const_iterable_t iterable(const T & itable) 34 | { 35 | return const_iterable_t(itable); 36 | } 37 | 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/mioinitsol.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: mioinitsol.py 5 | # 6 | # Purpose: Demonstrates how to solve a small mixed 7 | # integer linear optimization problem 8 | # providing an initial feasible solution. 9 | ## 10 | import sys 11 | from mosek.fusion import * 12 | 13 | def main(args): 14 | c = [7.0, 10.0, 1.0, 5.0] 15 | 16 | with Model('mioinitsol') as M: 17 | n = 4 18 | 19 | x = M.variable('x', n, Domain.greaterThan(0.0)) 20 | x.slice(0,3).makeInteger() 21 | 22 | M.constraint(Expr.sum(x), Domain.lessThan(2.5)) 23 | 24 | # Set the objective function to (c^T * x) 25 | M.objective('obj', ObjectiveSense.Maximize, Expr.dot(c, x)) 26 | 27 | # Assign values to integer variables. 28 | # We only set a slice of xx 29 | init_sol = [1.0, 1.0, 0.0] 30 | x.slice(0,3).setLevel(init_sol) 31 | 32 | # Solve the problem 33 | M.setLogHandler(sys.stdout) 34 | M.solve() 35 | 36 | # Get the solution values 37 | ss = M.getPrimalSolutionStatus() 38 | print("Solution status: {0}".format(ss)) 39 | sol = x.level() 40 | print('x = {0}'.format(sol)) 41 | 42 | # Was the initial solution used? 43 | constr = M.getSolverIntInfo("mioConstructSolution") 44 | constrVal = M.getSolverDoubleInfo("mioConstructSolutionObj") 45 | print("Initial solution utilization: {0}\nInitial solution objective: {1:.3f}\n".format(constr, constrVal)) 46 | 47 | if __name__ == '__main__': 48 | main(sys.argv[1:]) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/ampl/diet.dat: -------------------------------------------------------------------------------- 1 | param: FOOD: cost f_min f_max := 2 | "Quarter Pounder w/ Cheese" 1.84 . . 3 | "McLean Deluxe w/ Cheese" 2.19 . . 4 | "Big Mac" 1.84 . . 5 | "Filet-O-Fish" 1.44 . . 6 | "McGrilled Chicken" 2.29 . . 7 | "Fries, small" .77 . . 8 | "Sausage McMuffin" 1.29 . . 9 | "1% Lowfat Milk" .60 . . 10 | "Orange Juice" .72 . . ; 11 | 12 | param: NUTR: n_min n_max := 13 | Cal 2000 . 14 | Carbo 350 375 15 | Protein 55 . 16 | VitA 100 . 17 | VitC 100 . 18 | Calc 100 . 19 | Iron 100 . ; 20 | 21 | param amt (tr): 22 | Cal Carbo Protein VitA VitC Calc Iron := 23 | "Quarter Pounder w/ Cheese" 510 34 28 15 6 30 20 24 | "McLean Deluxe w/ Cheese" 370 35 24 15 10 20 20 25 | "Big Mac" 500 42 25 6 2 25 20 26 | "Filet-O-Fish" 370 38 14 2 0 15 10 27 | "McGrilled Chicken" 400 42 31 8 15 15 8 28 | "Fries, small" 220 26 3 0 15 0 2 29 | "Sausage McMuffin" 345 27 15 4 0 20 15 30 | "1% Lowfat Milk" 110 12 9 10 4 30 0 31 | "Orange Juice" 80 20 1 2 120 2 2 ; 32 | 33 | 34 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/mioinitsol.java: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: mioinitsol.java 5 | // 6 | // Purpose: Demonstrates how to solve a small mixed 7 | // integer linear optimization problem. 8 | // 9 | package com.mosek.fusion.examples; 10 | import mosek.fusion.*; 11 | 12 | public class mioinitsol { 13 | public static void main(String[] args) 14 | throws SolutionError { 15 | int n = 4; 16 | double[] c = { 7.0, 10.0, 1.0, 5.0 }; 17 | 18 | Model M = new Model("mioinitsol"); 19 | try { 20 | Variable x = M.variable("x", n, Domain.greaterThan(0.0)); 21 | x.slice(0,3).makeInteger(); 22 | 23 | M.constraint(Expr.sum(x), Domain.lessThan(2.5)); 24 | 25 | M.objective("obj", ObjectiveSense.Maximize, Expr.dot(c, x)); 26 | 27 | // Assign values to integer variables. 28 | // We only set a slice of x 29 | double[] init_sol = { 1, 1, 0 }; 30 | x.slice(0,3).setLevel( init_sol ); 31 | 32 | M.solve(); 33 | 34 | // Get the solution values 35 | double[] sol = x.level(); 36 | System.out.printf("x = ["); 37 | for (int i = 0; i < n; i++) { 38 | System.out.printf("%e, ", sol[i]); 39 | } 40 | System.out.printf("]\n"); 41 | 42 | // Was the initial solution used? 43 | int constr = M.getSolverIntInfo("mioConstructSolution"); 44 | double constrVal = M.getSolverDoubleInfo("mioConstructSolutionObj"); 45 | System.out.println("Initial solution utilization: " + constr); 46 | System.out.println("Initial solution objective: " + constrVal); 47 | 48 | } finally { 49 | M.dispose(); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/mico1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: mico1.py 5 | # 6 | # Purpose: Demonstrates how to solve a small mixed 7 | # integer conic optimization problem. 8 | # 9 | # minimize x^2 + y^2 10 | # subject to x >= e^y + 3.8 11 | # x, y - integer 12 | ## 13 | import mosek, sys 14 | 15 | # Define a stream printer to grab output from MOSEK 16 | def streamprinter(text): 17 | sys.stdout.write(text) 18 | sys.stdout.flush() 19 | 20 | with mosek.Env() as env: 21 | with env.Task(0, 0) as task: 22 | task.set_Stream(mosek.streamtype.log, streamprinter) 23 | 24 | task.appendvars(6) 25 | task.appendcons(3) 26 | task.putvarboundsliceconst(0, 6, mosek.boundkey.fr, -0.0, 0.0) 27 | 28 | # Integrality constraints 29 | task.putvartypelist([1,2], [mosek.variabletype.type_int]*2) 30 | 31 | # Set up the three auxiliary linear constraints 32 | task.putaijlist([0,0,1,2,2], 33 | [1,3,4,2,5], 34 | [-1,1,1,1,-1]) 35 | task.putconboundslice(0, 3, [mosek.boundkey.fx]*3, [-3.8, 1, 0], [-3.8, 1, 0]) 36 | 37 | # Objective 38 | task.putobjsense(mosek.objsense.minimize) 39 | task.putcj(0, 1) 40 | 41 | # Conic part of the problem 42 | task.appendconesseq([mosek.conetype.quad, mosek.conetype.pexp], [0, 0], [3, 3], 0) 43 | 44 | # Optimize the task 45 | task.optimize() 46 | task.solutionsummary(mosek.streamtype.msg) 47 | 48 | xx = [0, 0] 49 | task.getxxslice(mosek.soltype.itg, 1, 3, xx) 50 | print(xx) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/feasrepairex1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : feasrepairex1.py 5 | # 6 | # Purpose : To demonstrate how to use the MSK_relaxprimal function to 7 | # locate the cause of an infeasibility. 8 | # 9 | # Syntax : On command line 10 | # python feasrepairex1.py feasrepair.lp 11 | # feasrepair.lp is located in mosek\\tools\examples. 12 | ## 13 | import sys 14 | import mosek 15 | 16 | # Since the actual value of Infinity is ignores, we define it solely 17 | # for symbolic purposes: 18 | inf = 0.0 19 | 20 | # Define a stream printer to grab output from MOSEK 21 | def streamprinter(text): 22 | sys.stdout.write(text) 23 | sys.stdout.flush() 24 | 25 | 26 | def main(inputfile): 27 | # Make a MOSEK environment 28 | with mosek.Env() as env: 29 | with env.Task(0, 0) as task: 30 | # Attach a printer to the task 31 | task.set_Stream(mosek.streamtype.log, streamprinter) 32 | 33 | # Read data 34 | task.readdata(inputfile) 35 | 36 | task.putintparam(mosek.iparam.log_feas_repair, 3) 37 | 38 | task.primalrepair(None, None, None, None) 39 | 40 | sum_viol = task.getdouinf(mosek.dinfitem.primal_repair_penalty_obj) 41 | print("Minimized sum of violations = %e" % sum_viol) 42 | 43 | task.optimize() 44 | 45 | task.solutionsummary(mosek.streamtype.msg) 46 | 47 | # call the main function 48 | try: 49 | filename = "../data/feasrepair.lp" 50 | if len(sys.argv) > 1: 51 | filename = sys.argv[1] 52 | main(filename) 53 | except Exception as e: 54 | print(e) 55 | raise -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/parameters.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : parameters.cc 5 | 6 | Purpose : Demonstrates a very simple example about how to set 7 | parameters and read information items 8 | with MOSEK Fusion 9 | */ 10 | #include 11 | #include "fusion.h" 12 | 13 | using namespace mosek::fusion; 14 | using namespace monty; 15 | 16 | int main(int argc, char ** argv) 17 | { 18 | Model::t M = new Model(""); auto _M = finally([&]() { M->dispose(); }); 19 | std::cout << "Test MOSEK parameter get/set functions\n"; 20 | 21 | // Set log level (integer parameter) 22 | M->setSolverParam("log", 1); 23 | // Select interior-point optimizer... (parameter with symbolic string values) 24 | M->setSolverParam("optimizer", "intpnt"); 25 | // ... without basis identification (parameter with symbolic string values) 26 | M->setSolverParam("intpntBasis", "never"); 27 | // Set relative gap tolerance (double parameter) 28 | M->setSolverParam("intpntCoTolRelGap", 1.0e-7); 29 | 30 | // The same in a different way 31 | M->setSolverParam("intpntCoTolRelGap", "1.0e-7"); 32 | 33 | // Incorrect value 34 | try { 35 | M->setSolverParam("intpntCoTolRelGap", -1); 36 | } 37 | catch (mosek::fusion::ParameterError) { 38 | std::cout << "Wrong parameter value\n"; 39 | } 40 | 41 | // Define and solve an optimization problem here 42 | // M->solve() 43 | // After optimization: 44 | 45 | std::cout << "Get MOSEK information items\n"; 46 | 47 | double tm = M->getSolverDoubleInfo("optimizerTime"); 48 | int it = M->getSolverIntInfo("intpntIter"); 49 | 50 | std::cout << "Time: " << tm << "\nIterations: " << it << "\n"; 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/java/blas_lapack.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : blas_lapack.java 5 | 6 | Purpose : To demonstrate how to call BLAS/LAPACK routines for whose MOSEK provides simplified interfaces. 7 | */ 8 | package com.mosek.example; 9 | 10 | public class blas_lapack { 11 | static final int n = 3, m = 2, k = 3; 12 | 13 | public static void main (String[] args) { 14 | 15 | double alpha = 2.0, beta = 0.5; 16 | double[] x = {1., 1., 1.}; 17 | double[] y = {1., 2., 3.}; 18 | double[] z = {1.0, 1.0}; 19 | 20 | /*A has m=2 rows and k=3 cols*/ 21 | double[] A = {1., 1., 2., 2., 3., 3.}; 22 | /*B has k=3 rows and n=3 cols*/ 23 | double[] B = {1., 1., 1., 1., 1., 1., 1., 1., 1.}; 24 | double[] C = { 1., 2., 3., 4., 5., 6.}; 25 | 26 | double[] D = {1.0, 1.0, 1.0, 1.0}; 27 | double[] Q = {1.0, 0.0, 0.0, 2.0}; 28 | double[] v = new double[2]; 29 | 30 | double[] xy = {0.}; 31 | 32 | try (mosek.Env env = new mosek.Env()) { 33 | /* routines*/ 34 | 35 | env.dot(n, x, y, xy); 36 | 37 | env.axpy(n, alpha, x, y); 38 | 39 | env.gemv(mosek.transpose.no, m, n, alpha, A, x, beta, z); 40 | 41 | env.gemm(mosek.transpose.no, mosek.transpose.no, m, n, k, alpha, A, B, beta, C); 42 | 43 | env.syrk(mosek.uplo.lo, mosek.transpose.no, m, k, alpha, A, beta, D); 44 | 45 | /* LAPACK routines*/ 46 | 47 | env.potrf(mosek.uplo.lo, m, Q); 48 | 49 | env.syeig(mosek.uplo.lo, m, Q, v); 50 | 51 | env.syevd(mosek.uplo.lo, m, Q, v); 52 | 53 | } catch (mosek.Exception e) { 54 | System.out.println ("An error/warning was encountered"); 55 | System.out.println (e.toString()); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/affco2.R: -------------------------------------------------------------------------------- 1 | ## 2 | # File : affco2.R 3 | # 4 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 5 | # 6 | # Description : 7 | # Implements a basic tutorial example with affine conic constraints: 8 | # 9 | # minimize t 10 | # st. (d, z1*y1,... zn*yn) \in Q^{n+1} 11 | # (yi, 1, ai*t) \in EXP, i=1,\ldots,n 12 | # 13 | # with input ai<0, zi, d. 14 | # 15 | # See also https://docs.mosek.com/modeling-cookbook/expo.html#hitting-time-of-a-linear-system 16 | # 17 | ## 18 | library("Rmosek") 19 | 20 | firstHittingTime <- function(n, z, a, d) 21 | { 22 | prob <- list(sense="min") 23 | # Variables [t, y1, ..., yn] 24 | prob$A <- Matrix(nrow=0, ncol=n+1) 25 | prob$bx<- rbind(rep(-Inf,n+1), rep(Inf,n+1)) 26 | prob$c <- c(1, rep(0, n)) 27 | 28 | # Quadratic cone 29 | FQ <- Diagonal(n+1, c(0, z)) 30 | gQ <- c(d, rep(0, n)) 31 | 32 | # All exponential cones 33 | FE <- sparseMatrix( c(seq(1,3*n,by=3), seq(3,3*n,by=3)), 34 | c(2:(n+1), rep(1,n)), 35 | x=c(rep(1,n), t(a))) 36 | gE <- rep(c(0, 1, 0), n) 37 | 38 | # Assemble input data 39 | prob$F <- rbind(FQ, FE) 40 | prob$g <- c(gQ, gE) 41 | prob$cones <- cbind(matrix(list("QUAD", 1+n, NULL), nrow=3, ncol=1), 42 | matrix(list("PEXP", 3, NULL), nrow=3, ncol=n)) 43 | rownames(prob$cones) <- c("type","dim","conepar") 44 | 45 | # Solve 46 | r <- mosek(prob, list(soldetail=1)) 47 | stopifnot(identical(r$response$code, 0)) 48 | 49 | r$sol$itr$xx[1] 50 | } 51 | 52 | n = 3 53 | z = c(3.3, 2.2, 1.3) 54 | a = c(-0.08, -0.3, -0.06) 55 | d = 0.5 56 | 57 | t <- firstHittingTime(n, z, a, d) 58 | print(sprintf("t = %.4e", t)) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/affco1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # File : affco1.R 3 | # 4 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 5 | # 6 | # Description : 7 | # Implements a basic tutorial example with affine conic constraints: 8 | # 9 | # maximize x_1^(1/3) + (x_1+x_2+0.1)^(1/4) 10 | # st. (x_1-0.5)^2 + (x_2-0.6)^2 <= 1 11 | # 0 <= x_1 <= x_2 + 1 12 | # 13 | ## 14 | library("Rmosek") 15 | 16 | affco1 <- function() 17 | { 18 | 19 | prob <- list(sense="max") 20 | 21 | # Variables [x1; x2; t1; t2] 22 | prob$c <- c(0, 0, 1, 1) 23 | 24 | # Linear inequality x_1 - x_2 <= 1 25 | prob$A <- Matrix(c(1, -1, 0, 0), nrow=1, sparse=TRUE) 26 | prob$bc <- rbind(blc=-Inf, buc=1) 27 | prob$bx <- rbind(blx=rep(-Inf,4), bux=rep(Inf,4)) 28 | 29 | # The quadratic cone 30 | FQ <- rbind(c(0,0,0,0), c(1,0,0,0), c(0,1,0,0)) 31 | gQ <- c(1, -0.5, -0.6) 32 | cQ <- matrix(list("QUAD", 3, NULL), nrow=3, ncol=1) 33 | 34 | # The power cone for (x_1, 1, t_1) \in POW3^(1/3,2/3) 35 | FP1 <- rbind(c(1,0,0,0), c(0,0,0,0), c(0,0,1,0)) 36 | gP1 <- c(0, 1, 0) 37 | cP1 <- matrix(list("PPOW", 3, c(1/3, 2/3)), nrow=3, ncol=1) 38 | 39 | # The power cone for (x_1+x_2+0.1, 1, t_2) \in POW3^(1/4,3/4) 40 | FP2 <- rbind(c(1,1,0,0), c(0,0,0,0), c(0,0,0,1)) 41 | gP2 <- c(0.1, 1, 0) 42 | cP2 <- matrix(list("PPOW", 3, c(1.0, 3.0)), nrow=3, ncol=1) 43 | 44 | # All cones 45 | prob$F <- rbind(FQ, FP1, FP2) 46 | prob$g <- cbind(gQ, gP1, gP2) 47 | prob$cones <- cbind(cQ, cP1, cP2) 48 | rownames(prob$cones) <- c("type","dim","conepar") 49 | 50 | r <- mosek(prob, list(soldetail=1)) 51 | stopifnot(identical(r$response$code, 0)) 52 | 53 | print(r$sol$itr$pobjval) 54 | print(r$sol$itr$xx[1:2]) 55 | } 56 | 57 | affco1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/lo1.java: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: lo1.java 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // maximize 3*x0 + 1*x1 + 5*x2 + x3 9 | // such that 10 | // 3*x0 + 1*x1 + 2*x2 = 30, 11 | // 2*x0 + 1*x1 + 3*x2 + 1*x3 > 15, 12 | // 2*x1 + + 3*x3 < 25 13 | // and 14 | // x0,x1,x2,x3 > 0, 15 | // 0 < x1 < 10 16 | //// 17 | package com.mosek.fusion.examples; 18 | import mosek.fusion.*; 19 | 20 | public class lo1 { 21 | public static void main(String[] args) 22 | throws SolutionError { 23 | double[][] A = 24 | { new double[] { 3.0, 1.0, 2.0, 0.0 }, 25 | new double[] { 2.0, 1.0, 3.0, 1.0 }, 26 | new double[] { 0.0, 2.0, 0.0, 3.0 } 27 | }; 28 | double[] c = { 3.0, 1.0, 5.0, 1.0 }; 29 | 30 | // Create a model with the name 'lo1' 31 | try(Model M = new Model("lo1")) 32 | { 33 | // Create variable 'x' of length 4 34 | Variable x = M.variable("x", 4, Domain.greaterThan(0.0)); 35 | 36 | // Create constraints 37 | M.constraint(x.index(1), Domain.lessThan(10.0)); 38 | M.constraint("c1", Expr.dot(A[0], x), Domain.equalsTo(30.0)); 39 | M.constraint("c2", Expr.dot(A[1], x), Domain.greaterThan(15.0)); 40 | M.constraint("c3", Expr.dot(A[2], x), Domain.lessThan(25.0)); 41 | 42 | // Set the objective function to (c^t * x) 43 | M.objective("obj", ObjectiveSense.Maximize, Expr.dot(c, x)); 44 | 45 | // Solve the problem 46 | M.solve(); 47 | 48 | // Get the solution values 49 | double[] sol = x.level(); 50 | System.out.printf("[x0,x1,x2,x3] = [%e, %e, %e, %e]\n", sol[0], sol[1], sol[2], sol[3]); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/lo1.cs: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: lo1.cs 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // maximize 3*x0 + 1*x1 + 5*x2 + x3 9 | // such that 10 | // 3*x0 + 1*x1 + 2*x2 = 30, 11 | // 2*x0 + 1*x1 + 3*x2 + 1*x3 > 15, 12 | // 2*x1 + + 3*x3 < 25 13 | // and 14 | // x0,x1,x2,x3 > 0, 15 | // 0 < x1 < 10 16 | //// 17 | using System; 18 | using mosek.fusion; 19 | namespace mosek.fusion.example 20 | { 21 | public class lo1 22 | { 23 | public static void Main(string[] args) 24 | { 25 | double[][] A = 26 | { new double[] { 3.0, 1.0, 2.0, 0.0 }, 27 | new double[] { 2.0, 1.0, 3.0, 1.0 }, 28 | new double[] { 0.0, 2.0, 0.0, 3.0 } 29 | }; 30 | double[] c = { 3.0, 1.0, 5.0, 1.0 }; 31 | 32 | // Create a model with the name 'lo1' 33 | Model M = new Model("lo1"); 34 | 35 | // Create variable 'x' of length 4 36 | Variable x = M.Variable("x", 4, Domain.GreaterThan(0.0)); 37 | 38 | // Create constraints 39 | M.Constraint(x.Index(1), Domain.LessThan(10.0)); 40 | 41 | M.Constraint("c1", Expr.Dot(A[0], x), Domain.EqualsTo(30.0)); 42 | M.Constraint("c2", Expr.Dot(A[1], x), Domain.GreaterThan(15.0)); 43 | M.Constraint("c3", Expr.Dot(A[2], x), Domain.LessThan(25.0)); 44 | 45 | // Set the objective function to (c^t * x) 46 | M.Objective("obj", ObjectiveSense.Maximize, Expr.Dot(c, x)); 47 | 48 | // Solve the problem 49 | M.Solve(); 50 | 51 | // Get the solution values 52 | double[] sol = x.Level(); 53 | Console.WriteLine("[x0,x1,x2,x3] = [{0}, {1}, {2}, {3} ]", sol[0], sol[1], sol[2], sol[3]); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(ott) 3 | 4 | find_package(Eigen3 REQUIRED) 5 | find_package(Boost 1.58 COMPONENTS system serialization REQUIRED) 6 | find_package(pybind11 REQUIRED) 7 | 8 | set(Eigen3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR}) 9 | include_directories(${Boost_INCLUDE_DIR}) 10 | include_directories(${PROJECT_SOURCE_DIR}/include) 11 | message("All Python Libraries will be in ${PROJECT_SOURCE_DIR}") 12 | 13 | # detect if on mac or unix, and include Mosek 14 | set(MOSEK_DIR ${PROJECT_SOURCE_DIR}/third_party/mosek/9/tools/platform) 15 | 16 | 17 | if(${UNIX}) 18 | message("Unix detected!") 19 | include_directories(${MOSEK_DIR}/osx64x86/h) 20 | link_directories(${MOSEK_DIR}/osx64x86/bin) 21 | elseif("${CMAKE_SYSTEM}" MATCHES "Linux") 22 | message("Linux detected!") 23 | link_directories(${MOSEK_DIR}/linux64x86/bin) 24 | include_directories(${MOSEK_DIR}/linux64x86/h) 25 | endif (${UNIX}) 26 | 27 | 28 | set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXXFLAGS} -O3 -Wall") 29 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin ) 30 | 31 | # libbezier module defines the matrices used in the optimization 32 | pybind11_add_module(bezier MODULE src/bezier_base.cpp src/bezier_wrapper.cpp include/ott/bezier_base.h) 33 | set_target_properties(bezier PROPERTIES 34 | LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}" 35 | PREFIX "lib") 36 | 37 | 38 | include_directories(${EIGEN3_INCLUDE_DIR}) 39 | pybind11_add_module(ott MODULE src/pybind_wrapper.cpp src/problem_constructor.cpp 40 | include/ott/pybind_box_type.h include/ott/data_types.h include/ott/TGProblem.h ) 41 | target_link_libraries(ott ${Boost_LIBRARIES}) 42 | 43 | set_target_properties(ott PROPERTIES 44 | LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}" 45 | PREFIX "lib") 46 | 47 | #add_subdirectory(src/snopt7) 48 | 49 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/mioinitsol.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: mioinitsol.cc 5 | // 6 | // Purpose: Demonstrates how to solve a small mixed 7 | // integer linear optimization problem 8 | // providing an initial feasible solution. 9 | // 10 | #include 11 | #include 12 | 13 | 14 | #include "fusion.h" 15 | 16 | using namespace mosek::fusion; 17 | using namespace monty; 18 | 19 | int main(int argc, char ** argv) 20 | { 21 | 22 | auto c = new_array_ptr({7.0, 10.0, 1.0, 5.0}); 23 | 24 | Model::t M = new Model("lo1"); auto _M = finally([&]() { M->dispose(); }); 25 | M->setLogHandler([ = ](const std::string & msg) { std::cout << msg << std::flush; } ); 26 | 27 | int n = c->size(); 28 | 29 | auto x = M->variable("x", n, Domain::greaterThan(0.0)); 30 | x->slice(0,3)->makeInteger(); 31 | 32 | M->constraint(Expr::sum(x), Domain::lessThan(2.5)); 33 | 34 | M->objective("obj", ObjectiveSense::Maximize, Expr::dot(c, x)); 35 | 36 | // Assign values to integer variables. 37 | // We only set a slice of x 38 | auto init_sol = new_array_ptr({ 1.0, 1.0, 0.0 }); 39 | x->slice(0,3)->setLevel( init_sol ); 40 | 41 | M->solve(); 42 | 43 | auto ss = M->getPrimalSolutionStatus(); 44 | std::cout << "Solution status: " << ss << std::endl; 45 | auto sol = x->level(); 46 | std::cout << "x = "; 47 | 48 | for (auto s : *sol) 49 | std::cout << s << ", "; 50 | 51 | // Was the initial solution used? 52 | int constr = M->getSolverIntInfo("mioConstructSolution"); 53 | double constrVal = M->getSolverDoubleInfo("mioConstructSolutionObj"); 54 | std::cout << "Initial solution utilization: " << constr << std::endl; 55 | std::cout << "Initial solution objective: " << constrVal << std::endl; 56 | 57 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/lo1.cc: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: lo1.cc 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // maximize 3*x0 + 1*x1 + 5*x2 + x3 9 | // such that 10 | // 3*x0 + 1*x1 + 2*x2 = 30, 11 | // 2*x0 + 1*x1 + 3*x2 + 1*x3 > 15, 12 | // 2*x1 + + 3*x3 < 25 13 | // and 14 | // x0,x1,x2,x3 > 0, 15 | // 0 < x1 < 10 16 | //// 17 | 18 | #include 19 | #include "fusion.h" 20 | using namespace mosek::fusion; 21 | using namespace monty; 22 | 23 | int main(int argc, char ** argv) 24 | { 25 | auto A1 = new_array_ptr({ 3.0, 1.0, 2.0, 0.0 }); 26 | auto A2 = new_array_ptr({ 2.0, 1.0, 3.0, 1.0 }); 27 | auto A3 = new_array_ptr({ 0.0, 2.0, 0.0, 3.0 }); 28 | auto c = new_array_ptr({ 3.0, 1.0, 5.0, 1.0 }); 29 | 30 | // Create a model with the name 'lo1' 31 | Model::t M = new Model("lo1"); auto _M = finally([&]() { M->dispose(); }); 32 | 33 | M->setLogHandler([ = ](const std::string & msg) { std::cout << msg << std::flush; } ); 34 | 35 | // Create variable 'x' of length 4 36 | Variable::t x = M->variable("x", 4, Domain::greaterThan(0.0)); 37 | 38 | // Create constraints 39 | M->constraint(x->index(1), Domain::lessThan(10.0)); 40 | M->constraint("c1", Expr::dot(A1, x), Domain::equalsTo(30.0)); 41 | M->constraint("c2", Expr::dot(A2, x), Domain::greaterThan(15.0)); 42 | M->constraint("c3", Expr::dot(A3, x), Domain::lessThan(25.0)); 43 | 44 | // Set the objective function to (c^t * x) 45 | M->objective("obj", ObjectiveSense::Maximize, Expr::dot(c, x)); 46 | 47 | // Solve the problem 48 | M->solve(); 49 | 50 | // Get the solution values 51 | auto sol = x->level(); 52 | std::cout << "[x0,x1,x2,x3] = " << (*sol) << "\n"; 53 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/milo1.java: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: milo1.java 5 | // 6 | // Purpose: Demonstrates how to solve a small mixed 7 | // integer linear optimization problem. 8 | // 9 | package com.mosek.fusion.examples; 10 | import mosek.fusion.*; 11 | 12 | public class milo1 { 13 | public static void main(String[] args) 14 | throws SolutionError { 15 | double[][] A = { 16 | { 50.0, 31.0 }, 17 | { 3.0, -2.0 } 18 | }; 19 | double[] c = { 1.0, 0.64 }; 20 | 21 | Model M = new Model("milo1"); 22 | try { 23 | Variable x = M.variable("x", 2, Domain.integral(Domain.greaterThan(0.0))); 24 | 25 | // Create the constraints 26 | // 50.0 x[0] + 31.0 x[1] <= 250.0 27 | // 3.0 x[0] - 2.0 x[1] >= -4.0 28 | M.constraint("c1", Expr.dot(A[0], x), Domain.lessThan(250.0)); 29 | M.constraint("c2", Expr.dot(A[1], x), Domain.greaterThan(-4.0)); 30 | 31 | // Set max solution time 32 | M.setSolverParam("mioMaxTime", 60.0); 33 | // Set max relative gap (to its default value) 34 | M.setSolverParam("mioTolRelGap", 1e-4); 35 | // Set max absolute gap (to its default value) 36 | M.setSolverParam("mioTolAbsGap", 0.0); 37 | 38 | // Set the objective function to (c^T * x) 39 | M.objective("obj", ObjectiveSense.Maximize, Expr.dot(c, x)); 40 | 41 | // Solve the problem 42 | M.solve(); 43 | 44 | // Get the solution values 45 | double[] sol = x.level(); 46 | System.out.printf("x1,x2 = %e, %e\n", sol[0], sol[1]); 47 | System.out.printf("MIP rel gap = %.2f (%f)\n", 48 | M.getSolverDoubleInfo("mioObjRelGap"), 49 | M.getSolverDoubleInfo("mioObjAbsGap")); 50 | } finally { 51 | M.dispose(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/sdo1.java: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: sdo1.java 5 | // 6 | // Purpose: 7 | // Solves the mixed semidefinite and conic quadratic optimization problem 8 | // 9 | // [2, 1, 0] 10 | // minimize Tr [1, 2, 1] * X + x0 11 | // [0, 1, 2] 12 | // 13 | // [1, 0, 0] 14 | // subject to Tr [0, 1, 0] * X + x0 = 1.0 15 | // [0, 0, 1] 16 | // 17 | // [1, 1, 1] 18 | // Tr [1, 1, 1] * X + x1 + x2 = 0.5 19 | // [1, 1, 1] 20 | // 21 | // X >> 0, x0 >= (x1^2 + x2^2) ^ (1/2) 22 | // 23 | package com.mosek.fusion.examples; 24 | import mosek.fusion.*; 25 | 26 | public class sdo1 { 27 | public static void main(String[] args) throws SolutionError { 28 | Model M = new Model("sdo1"); 29 | try { 30 | // Setting up the variables 31 | Variable X = M.variable("X", Domain.inPSDCone(3)); 32 | Variable x = M.variable("x", Domain.inQCone(3)); 33 | 34 | // Setting up constant coefficient matrices 35 | Matrix C = Matrix.dense ( new double[][] {{2., 1., 0.}, {1., 2., 1.}, {0., 1., 2.}} ); 36 | Matrix A1 = Matrix.eye(3); 37 | Matrix A2 = Matrix.ones(3,3); 38 | 39 | // Objective 40 | M.objective(ObjectiveSense.Minimize, Expr.add(Expr.dot(C, X), x.index(0))); 41 | 42 | // Constraints 43 | M.constraint("c1", Expr.add(Expr.dot(A1, X), x.index(0)), Domain.equalsTo(1.0)); 44 | M.constraint("c2", Expr.add(Expr.dot(A2, X), Expr.sum(x.slice(1, 3))), Domain.equalsTo(0.5)); 45 | 46 | M.solve(); 47 | 48 | System.out.println(java.util.Arrays.toString( X.level() )); 49 | System.out.println(java.util.Arrays.toString( x.level() )); 50 | } finally { 51 | M.dispose(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/mioinitsol.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: mioinitsol.cs 5 | // 6 | // Purpose: Demonstrates how to solve a small mixed 7 | // integer linear optimization problem 8 | // providing an initial feasible solution. 9 | // 10 | using System; 11 | using mosek.fusion; 12 | 13 | namespace mosek.fusion.example 14 | { 15 | public class mioinitsol 16 | { 17 | public static void Main(string[] args) 18 | { 19 | double[] c = { 7.0, 10.0, 1.0, 5.0 }; 20 | int n = 4; 21 | using (Model M = new Model("mioinitsol")) 22 | { 23 | 24 | Variable x = M.Variable("x", n, Domain.GreaterThan(0.0)); 25 | x.Slice(0,3).MakeInteger(); 26 | 27 | // Create the constraint 28 | M.Constraint(Expr.Sum(x), Domain.LessThan(2.5)); 29 | 30 | // Set the objective function to (c^T * x) 31 | M.Objective("obj", ObjectiveSense.Maximize, Expr.Dot(c, x)); 32 | 33 | // Assign values to integer variables. 34 | // We only set a slice of x 35 | double[] init_sol = { 1, 1, 0 }; 36 | x.Slice(0,3).SetLevel( init_sol ); 37 | 38 | // Solve the problem 39 | M.Solve(); 40 | 41 | // Get the solution values 42 | double[] sol = x.Level(); 43 | Console.Write("x = ["); 44 | for(int i=0;i= 2) { 37 | // If using OPF format, these parameters will specify what to include in output 38 | task.putintparam (mosek.iparam.opf_write_solutions, mosek.onoffkey.on.value); 39 | task.putintparam (mosek.iparam.opf_write_problem, mosek.onoffkey.on.value); 40 | task.putintparam (mosek.iparam.opf_write_hints, mosek.onoffkey.off.value); 41 | task.putintparam (mosek.iparam.opf_write_parameters, mosek.onoffkey.off.value); 42 | 43 | task.writedata (args[1]); 44 | } 45 | } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/sdo1.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: sdo1.cc 5 | // 6 | // Purpose: 7 | // Solves the mixed semidefinite and conic quadratic optimization problem 8 | // 9 | // [2, 1, 0] 10 | // minimize Tr [1, 2, 1] * X + x0 11 | // [0, 1, 2] 12 | // 13 | // [1, 0, 0] 14 | // subject to Tr [0, 1, 0] * X + x0 = 1.0 15 | // [0, 0, 1] 16 | // 17 | // [1, 1, 1] 18 | // Tr [1, 1, 1] * X + x1 + x2 = 0.5 19 | // [1, 1, 1] 20 | // 21 | // X >> 0, x0 >= (x1^2 + x2^2) ^ (1/2) 22 | // 23 | #include 24 | #include "fusion.h" 25 | 26 | using namespace mosek::fusion; 27 | using namespace monty; 28 | 29 | int main(int argc, char ** argv) 30 | { 31 | Model::t M = new Model("sdo1"); auto _M = finally([&]() { M->dispose(); }); 32 | 33 | // Setting up the variables 34 | Variable::t X = M->variable("X", Domain::inPSDCone(3)); 35 | Variable::t x = M->variable("x", Domain::inQCone(3)); 36 | 37 | // Setting up the constant coefficient matrices 38 | Matrix::t C = Matrix::dense ( new_array_ptr({{2., 1., 0.}, {1., 2., 1.}, {0., 1., 2.}})); 39 | Matrix::t A1 = Matrix::eye(3); 40 | Matrix::t A2 = Matrix::ones(3, 3); 41 | 42 | // Objective 43 | M->objective(ObjectiveSense::Minimize, Expr::add(Expr::dot(C, X), x->index(0))); 44 | 45 | // Constraints 46 | M->constraint("c1", Expr::add(Expr::dot(A1, X), x->index(0)), Domain::equalsTo(1.0)); 47 | M->constraint("c2", Expr::add(Expr::dot(A2, X), Expr::sum(x->slice(1, 3))), Domain::equalsTo(0.5)); 48 | 49 | M->solve(); 50 | 51 | std::cout << "Solution : " << std::endl; 52 | std::cout << " X = " << *(X->level()) << std::endl; 53 | std::cout << " x = " << *(x->level()) << std::endl; 54 | 55 | return 0; 56 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/milo1.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: milo1.cc 5 | // 6 | // Purpose: Demonstrates how to solve a small mixed 7 | // integer linear optimization problem. 8 | // 9 | #include 10 | #include 11 | #include "fusion.h" 12 | 13 | using namespace mosek::fusion; 14 | using namespace monty; 15 | 16 | int main(int argc, char ** argv) 17 | { 18 | auto a1 = new_array_ptr({ 50.0, 31.0 }); 19 | auto a2 = new_array_ptr({ 3.0, -2.0 }); 20 | auto c = new_array_ptr({ 1.0, 0.64 }); 21 | 22 | Model::t M = new Model("milo1"); auto _M = finally([&]() { M->dispose(); }); 23 | Variable::t x = M->variable("x", 2, Domain::integral(Domain::greaterThan(0.0))); 24 | 25 | // Create the constraints 26 | // 50.0 x[0] + 31.0 x[1] <= 250.0 27 | // 3.0 x[0] - 2.0 x[1] >= -4.0 28 | M->constraint("c1", Expr::dot(a1, x), Domain::lessThan(250.0)); 29 | M->constraint("c2", Expr::dot(a2, x), Domain::greaterThan(-4.0)); 30 | 31 | // Set max solution time 32 | M->setSolverParam("mioMaxTime", 60.0); 33 | // Set max relative gap (to its default value) 34 | M->setSolverParam("mioTolRelGap", 1e-4); 35 | // Set max absolute gap (to its default value) 36 | M->setSolverParam("mioTolAbsGap", 0.0); 37 | 38 | // Set the objective function to (c^T * x) 39 | M->objective("obj", ObjectiveSense::Maximize, Expr::dot(c, x)); 40 | 41 | // Solve the problem 42 | M->solve(); 43 | 44 | // Get the solution values 45 | auto sol = x->level(); 46 | std::cout << std::setiosflags(std::ios::scientific) << std::setprecision(2) 47 | << "x1 = " << (*sol)[0] << std::endl 48 | << "x2 = " << (*sol)[1] << std::endl 49 | << "MIP rel gap = " << M->getSolverDoubleInfo("mioObjRelGap") << " (" << M->getSolverDoubleInfo("mioObjAbsGap") << ")" << std::endl; 50 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/total_variation.java: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: total_variation.java 5 | // 6 | // Purpose: Demonstrates how to solve a total 7 | // variation problem using the Fusion API. 8 | // 9 | 10 | package com.mosek.fusion.examples; 11 | import java.util.Random; 12 | import mosek.fusion.*; 13 | 14 | public class total_variation { 15 | public static void main(String[] args) 16 | throws SolutionError { 17 | int ncols = 50; 18 | int nrows = 50; 19 | int seed = 0; 20 | double sigma = 1.0; 21 | int ncells = nrows * ncols; 22 | Random randGen = new Random(seed); 23 | 24 | double [] f = new double[ncells]; 25 | 26 | //Random signal with Gaussian noise 27 | for (int i = 0; i < ncells; i++) 28 | f[i] = Math.max( Math.min(1.0, randGen.nextDouble() + randGen.nextGaussian() * sigma), .0 ); 29 | 30 | 31 | Model M = new Model("TV"); 32 | try { 33 | Variable u = M.variable(new int[] {nrows + 1, ncols + 1}, Domain.inRange(0., 1.0)); 34 | Variable t = M.variable(new int[] {nrows, ncols}, Domain.unbounded()); 35 | 36 | Variable ucore = u.slice(new int[] {0, 0}, new int[] {nrows, ncols}); 37 | 38 | Expression deltax = Expr.sub( u.slice( new int[] {1, 0}, new int[] {nrows + 1, ncols} ), ucore ); 39 | Expression deltay = Expr.sub( u.slice( new int[] {0, 1}, new int[] {nrows, ncols + 1} ), ucore ); 40 | 41 | M.constraint( Expr.stack(2, t, deltax, deltay), Domain.inQCone().axis(2) ); 42 | 43 | M.constraint( Expr.vstack(sigma, Expr.flatten( Expr.sub( Matrix.dense(nrows, ncols, f), ucore ) ) ), 44 | Domain.inQCone() ); 45 | 46 | M.objective( ObjectiveSense.Minimize, Expr.sum(t) ); 47 | 48 | M.setLogHandler(new java.io.PrintWriter(System.out)); 49 | M.solve(); 50 | } finally { 51 | M.dispose(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/ceo1.java: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: ceo1.java 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // minimize x1 + x2 9 | // such that 10 | // x1 + x2 + x3 = 1.0 11 | // x1,x2 >= 0.0 12 | // and x1 >= x2 * exp(x3/x2) 13 | // 14 | 15 | package com.mosek.fusion.examples; 16 | import mosek.fusion.*; 17 | 18 | public class ceo1 { 19 | public static void main(String[] args) 20 | throws SolutionError { 21 | Model M = new Model("ceo1"); 22 | try { 23 | Variable x = M.variable("x", 3, Domain.unbounded()); 24 | 25 | // Create the constraint 26 | // x[0] + x[1] + x[2] = 1.0 27 | M.constraint("lc", Expr.sum(x), Domain.equalsTo(1.0)); 28 | 29 | // Create the conic exponential constraint 30 | Constraint expc = M.constraint("expc", x, Domain.inPExpCone()); 31 | 32 | // Set the objective function to (x[0] + x[1]) 33 | M.objective("obj", ObjectiveSense.Minimize, Expr.sum(x.slice(0,2))); 34 | 35 | // Solve the problem 36 | M.solve(); 37 | 38 | // Get the linear solution values 39 | double[] solx = x.level(); 40 | System.out.printf("x1,x2,x3 = %e, %e, %e\n", solx[0], solx[1], solx[2]); 41 | 42 | // Get conic solution of expc 43 | double[] expclvl = expc.level(); 44 | double[] expcsn = expc.dual(); 45 | 46 | System.out.printf("expc levels = %e", expclvl[0]); 47 | for (int i = 1; i < expclvl.length; ++i) 48 | System.out.printf(", %e", expclvl[i]); 49 | System.out.print("\n"); 50 | 51 | System.out.printf("expc dual conic var levels = %e", expcsn[0]); 52 | for (int i = 1; i < expcsn.length; ++i) 53 | System.out.printf(", %e", expcsn[i]); 54 | System.out.print("\n"); 55 | 56 | } finally { 57 | M.dispose(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/ceo1.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: ceo1.cs 5 | // 6 | // Purpose: Demonstrates how to solve the problem 7 | // 8 | // minimize x1 + x2 9 | // such that 10 | // x1 + x2 + x3 = 1.0 11 | // x1,x2 >= 0.0 12 | // and x1 >= x2 * exp(x3/x2) 13 | // 14 | using System; 15 | using mosek.fusion; 16 | 17 | namespace mosek.fusion.example 18 | { 19 | public class ceo1 20 | { 21 | public static void Main(string[] args) 22 | { 23 | using (Model M = new Model("ceo1")) 24 | { 25 | 26 | Variable x = M.Variable("x", 3, Domain.Unbounded()); 27 | 28 | // Create the constraint 29 | // x[0] + x[1] + x[2] = 1.0 30 | M.Constraint("lc", Expr.Sum(x), Domain.EqualsTo(1.0)); 31 | 32 | // Create the exponential conic constraint 33 | Constraint expc = M.Constraint("expc", x, Domain.InPExpCone()); 34 | 35 | // Set the objective function to (x[0] + x[1]) 36 | M.Objective("obj", ObjectiveSense.Minimize, Expr.Sum(x.Slice(0,2))); 37 | 38 | // Solve the problem 39 | M.Solve(); 40 | 41 | // Get the linear solution values 42 | double[] solx = x.Level(); 43 | Console.WriteLine("x1,x2,x3 = {0}, {1}, {2}", solx[0], solx[1], solx[2]); 44 | 45 | // Get conic solution of expc 46 | double[] expclvl = expc.Level(); 47 | double[] expcsn = expc.Dual(); 48 | 49 | Console.Write("expc levels = {0}", expclvl[0]); 50 | for (int i = 1; i < expclvl.Length; ++i) 51 | Console.Write(", {0}", expclvl[i]); 52 | Console.WriteLine(); 53 | 54 | Console.Write("expc dual conic var levels = {0}", expcsn[0]); 55 | for (int i = 1; i < expcsn.Length; ++i) 56 | Console.Write(", {0}", expcsn[i]); 57 | Console.WriteLine(); 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/parameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : parameters.java 5 | 6 | Purpose : Demonstrates a very simple example about how to set 7 | parameters and read information items 8 | with MOSEK Fusion 9 | */ 10 | package com.mosek.fusion.examples; 11 | import mosek.*; 12 | import mosek.fusion.*; 13 | 14 | public class parameters { 15 | public static void main(String[] argv) { 16 | // Create the Model 17 | Model M = new Model(); 18 | System.out.println("Test MOSEK parameter get/set functions"); 19 | 20 | // Set log level (integer parameter) 21 | M.setSolverParam("log", 1); 22 | // Select interior-point optimizer... (parameter with symbolic string values) 23 | M.setSolverParam("optimizer", "intpnt"); 24 | // ... without basis identification (parameter with symbolic string values) 25 | M.setSolverParam("intpntBasis", "never"); 26 | // Set relative gap tolerance (double parameter) 27 | M.setSolverParam("intpntCoTolRelGap", 1.0e-7); 28 | 29 | // The same in a different way 30 | M.setSolverParam("intpntCoTolRelGap", "1.0e-7"); 31 | 32 | // Incorrect value 33 | try { 34 | M.setSolverParam("intpntCoTolRelGap", -1); 35 | } 36 | catch (mosek.fusion.ParameterError e) { 37 | System.out.println("Wrong parameter value"); 38 | } 39 | 40 | 41 | // Define and solve an optimization problem here 42 | // M.solve() 43 | // After optimization: 44 | 45 | System.out.println("Get MOSEK information items"); 46 | 47 | double tm = M.getSolverDoubleInfo("optimizerTime"); 48 | int it = M.getSolverIntInfo("intpntIter"); 49 | 50 | System.out.println("Time: " + tm); 51 | System.out.println("Iterations: " + it); 52 | } 53 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/milo1.cs: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 4 | // 5 | // File: milo1.cs 6 | // 7 | // Purpose: Demonstrates how to solve a small mixed 8 | // integer linear optimization problem. 9 | // 10 | using System; 11 | using mosek.fusion; 12 | 13 | namespace mosek.fusion.example 14 | { 15 | public class milo1 16 | { 17 | public static void Main(string[] args) 18 | { 19 | double[][] A = 20 | { new double[] { 50.0, 31.0 }, 21 | new double[] { 3.0, -2.0 } 22 | }; 23 | double[] c = { 1.0, 0.64 }; 24 | using (Model M = new Model("milo1")) 25 | { 26 | Variable x = M.Variable("x", 2, Domain.Integral(Domain.GreaterThan(0.0))); 27 | 28 | // Create the constraints 29 | // 50.0 x[0] + 31.0 x[1] <= 250.0 30 | // 3.0 x[0] - 2.0 x[1] >= -4.0 31 | M.Constraint("c1", Expr.Dot(A[0], x), Domain.LessThan(250.0)); 32 | M.Constraint("c2", Expr.Dot(A[1], x), Domain.GreaterThan(-4.0)); 33 | 34 | // Set max solution time 35 | M.SetSolverParam("mioMaxTime", 60.0); 36 | // Set max relative gap (to its default value) 37 | M.SetSolverParam("mioTolRelGap", 1e-4); 38 | // Set max absolute gap (to its default value) 39 | M.SetSolverParam("mioTolAbsGap", 0.0); 40 | 41 | // Set the objective function to (c^T * x) 42 | M.Objective("obj", ObjectiveSense.Maximize, Expr.Dot(c, x)); 43 | 44 | // Solve the problem 45 | M.Solve(); 46 | 47 | // Get the solution values 48 | double[] sol = x.Level(); 49 | Console.WriteLine("x1,x2 = {0}, {1}", sol[0], sol[1]); 50 | double miorelgap = M.GetSolverDoubleInfo("mioObjRelGap"); 51 | double mioabsgap = M.GetSolverDoubleInfo("mioObjAbsGap"); 52 | Console.WriteLine("MIP rel gap = {0} ({0})", miorelgap, mioabsgap); 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/sdo1.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: sdo1.cs 5 | // 6 | // Purpose: 7 | // Solves the mixed semidefinite and conic quadratic optimization problem 8 | // 9 | // [2, 1, 0] 10 | // minimize Tr [1, 2, 1] * X + x0 11 | // [0, 1, 2] 12 | // 13 | // [1, 0, 0] 14 | // subject to Tr [0, 1, 0] * X + x0 = 1.0 15 | // [0, 0, 1] 16 | // 17 | // [1, 1, 1] 18 | // Tr [1, 1, 1] * X + x1 + x2 = 0.5 19 | // [1, 1, 1] 20 | // 21 | // X >> 0, x0 >= (x1^2 + x2^2) ^ (1/2) 22 | // 23 | using System; 24 | using mosek.fusion; 25 | 26 | namespace mosek.fusion.example 27 | { 28 | public class sdo1 29 | { 30 | public static void Main(string[] args) 31 | { 32 | using (Model M = new Model("sdo1")) 33 | { 34 | // Setting up the variables 35 | Variable X = M.Variable("X", Domain.InPSDCone(3)); 36 | Variable x = M.Variable("x", Domain.InQCone(3)); 37 | 38 | // Setting up constant coefficient matrices 39 | Matrix C = Matrix.Dense ( new double[,] { {2, 1, 0}, {1, 2, 1}, {0, 1, 2}} ); 40 | Matrix A1 = Matrix.Eye(3); 41 | Matrix A2 = Matrix.Ones(3,3); 42 | 43 | // Objective 44 | M.Objective(ObjectiveSense.Minimize, Expr.Add(Expr.Dot(C, X), x.Index(0))); 45 | 46 | // Constraints 47 | M.Constraint("c1", Expr.Add(Expr.Dot(A1, X), x.Index(0)), Domain.EqualsTo(1.0)); 48 | M.Constraint("c2", Expr.Add(Expr.Dot(A2, X), Expr.Sum(x.Slice(1, 3))), 49 | Domain.EqualsTo(0.5)); 50 | 51 | M.Solve(); 52 | 53 | Console.WriteLine("[{0}]", (new Utils.StringBuffer()).A(X.Level()).ToString()); 54 | Console.WriteLine("[{0}]", (new Utils.StringBuffer()).A(x.Level()).ToString()); 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/parameters.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : parameters.cs 5 | 6 | Purpose : Demonstrates a very simple example about how to set 7 | parameters and read information items 8 | with MOSEK Fusion 9 | */ 10 | using System; 11 | using mosek.fusion; 12 | 13 | namespace mosek.fusion.example 14 | { 15 | public class parameters 16 | { 17 | public static void Main(string[] args) 18 | { 19 | // Create the Model 20 | using (Model M = new Model()) { 21 | Console.WriteLine("Test MOSEK parameter get/set functions"); 22 | 23 | // Set log level (integer parameter) 24 | M.SetSolverParam("log", 1); 25 | // Select interior-point optimizer... (parameter with symbolic string values) 26 | M.SetSolverParam("optimizer", "intpnt"); 27 | // ... without basis identification (parameter with symbolic string values) 28 | M.SetSolverParam("intpntBasis", "never"); 29 | // Set relative gap tolerance (double parameter) 30 | M.SetSolverParam("intpntCoTolRelGap", 1.0e-7); 31 | 32 | // The same in a different way 33 | // M.SetSolverParam("intpntCoTolRelGap", "1.0e-7"); 34 | 35 | // Incorrect value 36 | try { 37 | M.SetSolverParam("intpntCoTolRelGap", -1); 38 | } 39 | catch (mosek.fusion.ParameterError e) { 40 | Console.WriteLine("Wrong parameter value"); 41 | } 42 | 43 | 44 | // Define and solve an optimization problem here 45 | // M.Solve() 46 | // After optimization: 47 | 48 | Console.WriteLine("Get MOSEK information items"); 49 | 50 | double tm = M.GetSolverDoubleInfo("optimizerTime"); 51 | int it = M.GetSolverIntInfo("intpntIter"); 52 | 53 | Console.WriteLine("Time: " + tm); 54 | Console.WriteLine("Iterations: " + it); 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/simple.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : simple.py 5 | # 6 | # Purpose : Demonstrates a very simple example using MOSEK by 7 | # reading a problem file, solving the problem and 8 | # writing the solution to a file. 9 | ## 10 | import mosek 11 | import sys 12 | 13 | def streamprinter(msg): 14 | sys.stdout.write(msg) 15 | sys.stdout.flush() 16 | 17 | if len(sys.argv) <= 1: 18 | print("Missing argument, syntax is:") 19 | print(" simple inputfile [ solutionfile ]") 20 | else: 21 | # Create the mosek environment. 22 | with mosek.Env() as env: 23 | 24 | # Create a task object linked with the environment env. 25 | # We create it with 0 variables and 0 constraints initially, 26 | # since we do not know the size of the problem. 27 | with env.Task(0, 0) as task: 28 | task.set_Stream(mosek.streamtype.log, streamprinter) 29 | 30 | # We assume that a problem file was given as the first command 31 | # line argument (received in `argv') 32 | 33 | task.readdata(sys.argv[1]) 34 | 35 | # Solve the problem 36 | task.optimize() 37 | 38 | # Print a summary of the solution 39 | task.solutionsummary(mosek.streamtype.log) 40 | 41 | # If an output file was specified, save problem to a file 42 | if len(sys.argv) >= 3: 43 | # If using OPF format, these parameters will specify what to include in output 44 | task.putintparam(mosek.iparam.opf_write_solutions, mosek.onoffkey.on) 45 | task.putintparam(mosek.iparam.opf_write_problem, mosek.onoffkey.on) 46 | task.putintparam(mosek.iparam.opf_write_hints, mosek.onoffkey.off) 47 | task.putintparam(mosek.iparam.opf_write_parameters, mosek.onoffkey.off) 48 | 49 | task.writedata(sys.argv[2]) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/parameters.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : parameters.py 5 | # 6 | # Purpose : Demonstrates a very simple example about how to get/set 7 | # parameters with MOSEK Python API 8 | ## 9 | import mosek 10 | 11 | # Create the mosek environment. 12 | with mosek.Env() as env: 13 | # Create the mosek environment. 14 | with env.Task() as task: 15 | print('Test MOSEK parameter get/set functions') 16 | 17 | # Set log level (integer parameter) 18 | task.putintparam(mosek.iparam.log, 1) 19 | # Select interior-point optimizer... (integer parameter) 20 | task.putintparam(mosek.iparam.optimizer, mosek.optimizertype.intpnt) 21 | # ... without basis identification (integer parameter) 22 | task.putintparam(mosek.iparam.intpnt_basis, mosek.basindtype.never) 23 | # Set relative gap tolerance (double parameter) 24 | task.putdouparam(mosek.dparam.intpnt_co_tol_rel_gap, 1.0e-7) 25 | 26 | # The same using explicit string names 27 | task.putparam ("MSK_DPAR_INTPNT_CO_TOL_REL_GAP", "1.0e-7") 28 | task.putnadouparam("MSK_DPAR_INTPNT_CO_TOL_REL_GAP", 1.0e-7 ) 29 | 30 | # Incorrect value 31 | try: 32 | task.putdouparam(mosek.dparam.intpnt_co_tol_rel_gap, -1.0) 33 | except: 34 | print('Wrong parameter value') 35 | 36 | 37 | param = task.getdouparam(mosek.dparam.intpnt_co_tol_rel_gap) 38 | print('Current value for parameter intpnt_co_tol_rel_gap = {}'.format(param)) 39 | 40 | # Define and solve an optimization problem here 41 | # task.optimize() 42 | # After optimization: 43 | 44 | print('Get MOSEK information items') 45 | 46 | tm = task.getdouinf(mosek.dinfitem.optimizer_time) 47 | it = task.getintinf(mosek.iinfitem.intpnt_iter) 48 | 49 | print('Time: {0}\nIterations: {1}'.format(tm,it)) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/parallel.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: parallel.py 5 | # 6 | # Purpose: Demonstrates parallel optimization 7 | # 8 | import mosek, sys 9 | from threading import Thread 10 | 11 | # A run method to optimize a single task 12 | def runTask(num, task, res, trm): 13 | try: 14 | trm[num] = task.optimize(); 15 | res[num] = mosek.rescode.ok 16 | except mosek.MosekException as e: 17 | trm[num] = mosek.rescode.err_unknown 18 | res[num] = e.errno 19 | 20 | # Takes a list of tasks and optimizes them in parallel threads. The 21 | # response code and termination code from each optimization is 22 | # stored in ``res`` and ``trm``. 23 | def paropt(tasks): 24 | n = len(tasks) 25 | res = [ mosek.rescode.err_unknown ] * n 26 | trm = [ mosek.rescode.err_unknown ] * n 27 | 28 | # Start parallel optimizations, one per task 29 | jobs = [ Thread(target=runTask, args=(i, tasks[i], res, trm)) for i in range(n) ] 30 | for j in jobs: 31 | j.start() 32 | for j in jobs: 33 | j.join() 34 | 35 | return res, trm 36 | 37 | 38 | # Example of how to use ``paropt``. 39 | # Optimizes tasks whose names were read from command line. 40 | def main(argv): 41 | n = len(argv) - 1 42 | tasks = [] 43 | 44 | with mosek.Env() as env: 45 | for i in range(n): 46 | t = mosek.Task(env, 0, 0) 47 | t.readdata(argv[i+1]) 48 | # Each task will be single-threaded 49 | t.putintparam(mosek.iparam.intpnt_multi_thread, mosek.onoffkey.off) 50 | tasks.append(t) 51 | 52 | res, trm = paropt(tasks) 53 | 54 | for i in range(n): 55 | print("Task {0} res {1} trm {2} obj_val {3} time {4}".format( 56 | i, 57 | res[i], 58 | trm[i], 59 | tasks[i].getdouinf(mosek.dinfitem.intpnt_primal_obj), 60 | tasks[i].getdouinf(mosek.dinfitem.optimizer_time))) 61 | 62 | if __name__ == "__main__": 63 | main(sys.argv) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/c/errorreporting.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: errorreporting.c 5 | 6 | Purpose: To demonstrate how the error reporting can be customized. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include "mosek.h" 12 | 13 | static MSKrescodee MSKAPI handleresponse(MSKuserhandle_t handle, 14 | MSKrescodee r, 15 | const char msg[]) 16 | /* A custom response handler. */ 17 | { 18 | /* Find out if we had an error or warning */ 19 | MSKrescodetypee rct; 20 | MSK_getresponseclass(r, &rct); 21 | 22 | if (r == MSK_RES_OK) 23 | { 24 | /* Do nothing */ 25 | } 26 | else if (rct == MSK_RESPONSE_WRN) 27 | { 28 | printf("MOSEK reports warning number %d: %s\n", r, msg); 29 | r = MSK_RES_OK; 30 | } 31 | else if (rct == MSK_RESPONSE_ERR) 32 | { 33 | printf("MOSEK reports error number %d: %s\n", r, msg); 34 | } 35 | else 36 | { 37 | printf("Unexpected response %d: %s\n", r, msg); 38 | } 39 | 40 | return (r); 41 | } /* handlerespone */ 42 | 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | MSKenv_t env; 47 | MSKrescodee r; 48 | MSKtask_t task; 49 | 50 | r = MSK_makeenv(&env, NULL); 51 | 52 | if (r == MSK_RES_OK) 53 | { 54 | r = MSK_makeemptytask(env, &task); 55 | if (r == MSK_RES_OK) 56 | { 57 | /* 58 | * Input a custom warning and error handler function. 59 | */ 60 | 61 | MSK_putresponsefunc(task, handleresponse, NULL); 62 | 63 | /* User defined code goes here */ 64 | /* This will provoke an error */ 65 | 66 | if (r == MSK_RES_OK) 67 | r = MSK_putaij(task, 10, 10, 1.0); 68 | 69 | } 70 | MSK_deletetask(&task); 71 | } 72 | MSK_deleteenv(&env); 73 | 74 | printf("Return code - %d\n", r); 75 | 76 | if (r == MSK_RES_ERR_INDEX_IS_TOO_LARGE) 77 | return MSK_RES_OK; 78 | else 79 | return 1; 80 | } /* main */ -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/breaksolver.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: breaksolver.py 5 | # 6 | # Purpose: Show how to break a long-running task. 7 | ## 8 | 9 | import sys 10 | from mosek.fusion import * 11 | import random 12 | import threading 13 | import time 14 | 15 | def main(): 16 | 17 | timeout = 5 18 | 19 | n = 200 # number of binary variables 20 | m = n // 5 # number of constraints 21 | p = n // 5 # Each constraint picks p variables and requires that exactly half of them are 1 22 | 23 | R = random.Random(1234) 24 | 25 | print("Build problem...") 26 | with Model('SolveBinary') as M: 27 | M.setLogHandler(sys.stdout) 28 | 29 | x = M.variable("x", n, Domain.binary()) 30 | 31 | M.objective(ObjectiveSense.Minimize, Expr.sum(x)) 32 | M.setLogHandler(sys.stdout) 33 | 34 | L = list(range(n)) 35 | for i in range(m): 36 | R.shuffle(L) 37 | M.constraint(Expr.sum(x.pick(L[:p])), Domain.equalsTo(p // 2)) 38 | 39 | print("Start thread...") 40 | T = threading.Thread(target=M.solve) 41 | T0 = time.time() 42 | 43 | try: 44 | T.start() # optimization now running in background 45 | 46 | # Loop until we get a solution or you run out of patience and press 47 | # Ctrl-C 48 | while True: 49 | if not T.isAlive(): 50 | print("Solver terminated before anything happened!") 51 | break 52 | elif time.time() - T0 > timeout: 53 | print("Solver terminated due to timeout!") 54 | M.breakSolver() 55 | break 56 | except KeyboardInterrupt: 57 | print("Signalling the solver that it can give up now!") 58 | M.breakSolver() 59 | finally: 60 | try: 61 | T.join() # wait for the solver to return 62 | except: 63 | pass 64 | 65 | if __name__ == '__main__': 66 | main() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/blas_lapack.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : blas_lapack.py 5 | # 6 | # Purpose : To demonstrate how to call BLAS/LAPACK routines 7 | # for whose MOSEK provides simplified interfaces. 8 | ## 9 | import mosek 10 | 11 | def print_matrix(x, r, c): 12 | for i in range(r): 13 | print([x[j * r + i] for j in range(c)]) 14 | 15 | with mosek.Env() as env: 16 | 17 | n = 3 18 | m = 2 19 | k = 3 20 | 21 | alpha = 2.0 22 | beta = 0.5 23 | 24 | x = [1.0, 1.0, 1.0] 25 | y = [1.0, 2.0, 3.0] 26 | z = [1.0, 1.0] 27 | v = [0.0, 0.0] 28 | #A has m=2 rows and k=3 cols 29 | A = [1.0, 1.0, 2.0, 2.0, 3., 3.] 30 | #B has k=3 rows and n=3 cols 31 | B = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] 32 | C = [0.0 for i in range(n * m)] 33 | D = [1.0, 1.0, 1.0, 1.0] 34 | Q = [1.0, 0.0, 0.0, 2.0] 35 | 36 | # BLAS routines 37 | 38 | xy = env.dot(n, x, y) 39 | print("dot results= %f\n" % xy) 40 | 41 | env.axpy(n, alpha, x, y) 42 | print("\naxpy results is ") 43 | print_matrix(y, 1, len(y)) 44 | 45 | env.gemv(mosek.transpose.no, m, n, alpha, A, x, beta, z) 46 | print("\ngemv results is ") 47 | print_matrix(z, 1, len(z)) 48 | 49 | env.gemm(mosek.transpose.no, mosek.transpose.no, 50 | m, n, k, alpha, A, B, beta, C) 51 | print("\ngemm results is ") 52 | print_matrix(C, m, n) 53 | 54 | env.syrk(mosek.uplo.lo, mosek.transpose.no, m, k, alpha, A, beta, D) 55 | print("\nsyrk results is") 56 | print_matrix(D, m, m) 57 | 58 | # LAPACK routines 59 | 60 | env.potrf(mosek.uplo.lo, m, Q) 61 | print("\npotrf results is ") 62 | print_matrix(Q, m, m) 63 | 64 | 65 | env.syeig(mosek.uplo.lo, m, Q, v) 66 | print("\nsyeig results is") 67 | print_matrix(v, 1, m) 68 | 69 | 70 | env.syevd(mosek.uplo.lo, m, Q, v) 71 | print("\nsyevd results is") 72 | print('v: ') 73 | print_matrix(v, 1, m) 74 | print('Q: ') 75 | print_matrix(Q, m, m) 76 | 77 | print("Exiting...") -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/portfolio_1_basic.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : portfolio_1_basic.R 5 | # 6 | # Purpose : To implement a basic Markowitz optimization model computing 7 | # the optimal expected return and portfolio for a given risk. 8 | ## 9 | library("Rmosek") 10 | 11 | BasicMarkowitz <- function( 12 | n, # Number of assets 13 | mu, # An n-dimmensional vector of expected returns 14 | GT, # A matrix with n columns so (GT')*GT = covariance matrix 15 | x0, # Initial holdings 16 | w, # Initial cash holding 17 | gamma) # Maximum risk (=std. dev) accepted 18 | { 19 | prob <- list(sense="max") 20 | prob$c <- mu 21 | prob$A <- Matrix(1.0, ncol=n) 22 | prob$bc <- rbind(blc=w+sum(x0), 23 | buc=w+sum(x0)) 24 | prob$bx <- rbind(blx=rep(0.0,n), 25 | bux=rep(Inf,n)) 26 | 27 | # Specify the affine conic constraints. 28 | NUMCONES <- 1 29 | prob$F <- rbind( 30 | Matrix(0.0,ncol=n), 31 | GT 32 | ) 33 | prob$g <- c(gamma,rep(0,n)) 34 | prob$cones <- matrix(list(), nrow=3, ncol=NUMCONES) 35 | rownames(prob$cones) <- c("type","dim","conepar") 36 | 37 | prob$cones[-3,1] <- list("QUAD", n+1) 38 | 39 | # Solve the problem 40 | r <- mosek(prob,list(verbose=1)) 41 | stopifnot(identical(r$response$code, 0)) 42 | 43 | # Return the solution 44 | x <- r$sol$itr$xx 45 | list(expret=drop(mu %*% x), stddev=gamma, x=x) 46 | } 47 | 48 | # Example of input 49 | n <- 3; 50 | w <- 1.0; 51 | mu <- c(0.1073, 0.0737, 0.0627) 52 | x0 <- c(0.0, 0.0, 0.0) 53 | gammas <- c(0.035, 0.040, 0.050, 0.060, 0.070, 0.080, 0.090) 54 | GT <- rbind(c(0.1667, 0.0232, 0.0013 ), 55 | c(0.0000, 0.1033, -0.0022), 56 | c(0.0000, 0.0000, 0.0338 )) 57 | 58 | for (gamma in gammas) { 59 | r <- BasicMarkowitz(n,mu,GT,x0,w,gamma) 60 | print(sprintf('Expected return: %.4e Std. deviation: %.4e', r$expret, r$stddev)) 61 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/dotnet/simple.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: simple.cs 5 | 6 | Purpose: Demonstrates a very simple example using MOSEK by 7 | reading a problem file, solving the problem and 8 | writing the solution to a file. 9 | */ 10 | using System; 11 | 12 | namespace mosek.example 13 | { 14 | class msgclass : mosek.Stream 15 | { 16 | public override void streamCB (string msg) 17 | { 18 | Console.Write ("{0}", msg); 19 | } 20 | } 21 | 22 | public class simple 23 | { 24 | public static void Main (string[] args) 25 | { 26 | if (args.Length == 0) 27 | { 28 | Console.WriteLine ("Missing argument, syntax is:"); 29 | Console.WriteLine (" simple inputfile [ solutionfile ]"); 30 | } 31 | else 32 | { 33 | using (mosek.Env env = new mosek.Env()) 34 | { 35 | using (mosek.Task task = new mosek.Task(env)) 36 | { 37 | task.set_Stream (mosek.streamtype.log, new msgclass ()); 38 | 39 | // We assume that a problem file was given as the first command 40 | // line argument (received in `args') 41 | task.readdata (args[0]); 42 | 43 | // Solve the problem 44 | task.optimize (); 45 | 46 | // Print a summary of the solution 47 | task.solutionsummary (mosek.streamtype.log); 48 | 49 | // If an output file was specified, save problem to a file 50 | if (args.Length >= 2) 51 | { 52 | // If using OPF format, these parameters will specify what to include in output 53 | task.putintparam (mosek.iparam.opf_write_solutions, mosek.onoffkey.on); 54 | task.putintparam (mosek.iparam.opf_write_problem, mosek.onoffkey.on); 55 | task.putintparam (mosek.iparam.opf_write_hints, mosek.onoffkey.off); 56 | task.putintparam (mosek.iparam.opf_write_parameters, mosek.onoffkey.off); 57 | 58 | task.writedata(args[1]); 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/baker.py: -------------------------------------------------------------------------------- 1 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 2 | # 3 | # File: baker.py 4 | # 5 | # Purpose: Demonstrates a small linear problem. 6 | # 7 | # Source: "Linaer Algebra" by Knut Sydsaeter and Bernt Oeksendal. 8 | # 9 | # The problem: A baker has 150 kg flour, 22 kg sugar, 25 kg butter and two 10 | # recipes: 11 | # 1) Cakes, requiring 3.0 kg flour, 1.0 kg sugar and 1.2 kg butter per dozen. 12 | # 2) Breads, requiring 5.0 kg flour, 0.5 kg sugar and 0.5 kg butter per dozen. 13 | # Let the revenue per dozen cakes be $4 and the revenue per dozen breads be $6. 14 | # 15 | # We now wish to compute the combination of cakes and breads that will optimize 16 | # the total revenue. 17 | 18 | from mosek.fusion import * 19 | 20 | ingredientnames = ["Flour", "Sugar", "Butter"] 21 | stock = [150.0, 22.0, 25.0] 22 | recipe = [[3.0, 5.0], 23 | [1.0, 0.5], 24 | [1.2, 0.5]] 25 | productnames = ["Cakes", "Breads"] 26 | revenue = [4.0, 6.0] 27 | 28 | def main(args): 29 | with Model("Recipe") as M: 30 | # "production" defines the amount of each product to bake. 31 | production = M.variable("production", 32 | Set.make(productnames), 33 | Domain.greaterThan(0.0)) 34 | # The objective is to maximize the total revenue. 35 | M.objective("revenue", 36 | ObjectiveSense.Maximize, 37 | Expr.dot(revenue, production)) 38 | 39 | # The production is constrained by stock: 40 | M.constraint(Expr.mul(recipe, production), Domain.lessThan(stock)) 41 | # We set stdout as the loghandler 42 | M.setLogHandler(sys.stdout) 43 | # We solve and fetch the solution: 44 | M.solve() 45 | 46 | print("Solution:") 47 | res = production.level() 48 | for name, val in zip(productnames, res): 49 | print(" Number of %s : %.1f" % (name, val)) 50 | print(" Revenue : %.2f" % (res[0] * revenue[0] + res[1] * revenue[1])) 51 | 52 | if __name__ == '__main__': 53 | import sys 54 | main(sys.argv[1:]) 55 | sys.exit(0) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/dotnet/blas_lapack.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: blas_lapack.cs 5 | 6 | Purpose: To demonstrate how to call BLAS/LAPACK routines for whose MOSEK provides simplified interfaces. 7 | */ 8 | using System; 9 | 10 | namespace mosek.example 11 | { 12 | public class blas_lapack 13 | { 14 | public static void Main () 15 | { 16 | const int n = 3, m = 2, k = 2; 17 | 18 | double alpha = 2.0, beta = 0.5; 19 | double[] x = {1.0, 1.0, 1.0}; 20 | double[] y = {1.0, 2.0, 3.0}; 21 | double[] z = {1.0, 1.0}; 22 | 23 | /*A has m=2 rows and k=3 cols*/ 24 | double[] A = {1.0, 1.0, 2.0, 2.0, 3.0, 3.0}; 25 | /*B has k=3 rows and n=3 cols*/ 26 | double[] B = {1.0, 1.0, 1.0, 27 | 1.0, 1.0, 1.0, 28 | 1.0, 1.0, 1.0 29 | }; 30 | double[] C = {1.0, 2.0, 3.0, 31 | 4.0, 5.0, 6.0 32 | }; 33 | 34 | double[] D = {1.0, 1.0, 1.0, 1.0}; 35 | double[] Q = {1.0, 0.0, 0.0, 2.0}; 36 | double[] v = new double[2]; 37 | 38 | double xy; 39 | 40 | 41 | using (mosek.Env env = new mosek.Env()) 42 | { 43 | /* BLAS routines */ 44 | 45 | try 46 | { 47 | 48 | env.dot(n, x, y, out xy); 49 | 50 | env.axpy(n, alpha, x, y); 51 | 52 | env.gemv(mosek.transpose.no, m, n, alpha, A, x, beta, z); 53 | 54 | env.gemm(mosek.transpose.no, mosek.transpose.no, m, n, k, alpha, A, B, beta, C); 55 | 56 | env.syrk(mosek.uplo.lo, mosek.transpose.no, m, k, alpha, A, beta, D); 57 | 58 | /* LAPACK routines*/ 59 | 60 | env.potrf(mosek.uplo.lo, m, Q); 61 | 62 | env.syeig(mosek.uplo.lo, m, Q, v); 63 | 64 | env.syevd(mosek.uplo.lo, m, Q, v); 65 | } 66 | catch (mosek.Exception e) 67 | { 68 | Console.WriteLine (e.Code); 69 | Console.WriteLine (e); 70 | } 71 | finally 72 | { 73 | if (env != null) env.Dispose (); 74 | } 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/primal_svm.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: primal_svm.py 5 | # 6 | # Purpose: Implements a simple soft-margin SVM 7 | # using the Fusion API. 8 | # 9 | import mosek 10 | from mosek.fusion import * 11 | 12 | import random 13 | 14 | def primal_svm(m,n,X,y,CC): 15 | 16 | print("Number of data : %d"%m) 17 | print("Number of features: %d"%n) 18 | 19 | with Model() as M: 20 | 21 | w = M.variable('w' , n, Domain.unbounded()) 22 | t = M.variable('t' , 1, Domain.unbounded()) 23 | b = M.variable('b' , 1, Domain.unbounded()) 24 | xi = M.variable('xi', m, Domain.greaterThan(0.)) 25 | 26 | M.constraint( 27 | Expr.add( 28 | Expr.mulElm( y, 29 | Expr.sub( Expr.mul(X,w), Var.repeat(b,m) ) 30 | ), 31 | xi 32 | ), 33 | Domain.greaterThan( 1. ) ) 34 | 35 | M.constraint( Expr.vstack(1., t, w), Domain.inRotatedQCone() ) 36 | 37 | print (' c | b | w ') 38 | 39 | for C in CC: 40 | M.objective( ObjectiveSense.Minimize, Expr.add( t, Expr.mul(C, Expr.sum(xi) ) ) ) 41 | M.solve() 42 | 43 | try: 44 | cb = '{0:6} | {1:8f} | '.format(C,b.level()[0]) 45 | wstar =' '.join([ '{0:8f}'.format(wi) for wi in w.level()]) 46 | print (cb+wstar) 47 | except: 48 | pass; 49 | 50 | if __name__ == '__main__': 51 | 52 | CC=[ 500.0*i for i in range(10)] 53 | 54 | m = 50 55 | n = 3 56 | seed= 0 57 | 58 | random.seed(seed) 59 | nump= random.randint(0,50) 60 | numm= m - nump 61 | 62 | y = [ 1. for i in range(nump)] + \ 63 | [ -1. for i in range(numm)] 64 | 65 | mean = 1. 66 | var = 1. 67 | 68 | X= [ [ random.gauss( mean,var) for f in range(n) ] for i in range(nump)] + \ 69 | [ [ random.gauss(-mean,var) for f in range(n) ] for i in range(numm)] 70 | 71 | primal_svm(m,n,X,y,CC) 72 | 73 | 74 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/total_variation.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: total_variation.py 5 | # 6 | # Purpose: Demonstrates how to solve a total 7 | # variation problem using the Fusion API. 8 | ## 9 | import sys 10 | import mosek 11 | from mosek.fusion import * 12 | import numpy as np 13 | 14 | def total_var(n,m,f,sigma): 15 | with Model('TV') as M: 16 | 17 | u= M.variable( [n+1,m+1], Domain.inRange(0.,1.0) ) 18 | t= M.variable( [n,m], Domain.unbounded() ) 19 | 20 | ucore= u.slice( [0,0], [n,m] ) 21 | 22 | deltax= Expr.sub( u.slice( [1,0], [n+1,m] ), ucore) 23 | deltay= Expr.sub( u.slice( [0,1], [n,m+1] ), ucore) 24 | 25 | M.constraint( Expr.stack(2, t, deltax, deltay), Domain.inQCone().axis(2) ) 26 | 27 | fmat = Matrix.dense(n,m,f) 28 | M.constraint( Expr.vstack(sigma, Expr.flatten( Expr.sub( fmat, ucore ) ) ), 29 | Domain.inQCone() ) 30 | 31 | M.objective( ObjectiveSense.Minimize, Expr.sum(t) ) 32 | M.setLogHandler(sys.stdout) 33 | M.solve() 34 | 35 | return ucore.level() 36 | 37 | #Display 38 | def show(n,m,grid): 39 | try: 40 | import matplotlib 41 | matplotlib.use('Agg') #Remove to go interactive 42 | import matplotlib.pyplot as plt 43 | import matplotlib.cm as cm 44 | plt.imshow(np.reshape(grid, (n,m)), extent=(0,m,0,n), 45 | interpolation='nearest', cmap=cm.jet, 46 | vmin=0, vmax=1) 47 | plt.show() 48 | except: 49 | print (grid) 50 | 51 | #Handling a single example 52 | def example(n,m,signal,noise,rel_sigma): 53 | f = signal+noise 54 | show(n,m,signal) 55 | show(n,m,f) 56 | u = total_var(n,m,f,rel_sigma*n*m) 57 | show(n,m,u) 58 | 59 | if __name__ == '__main__': 60 | np.random.seed(0) 61 | 62 | #Example: Linear signal with Gaussian noise 63 | n,m=100,200 64 | u = example(n,m, 65 | np.reshape([[1.0*(i+j)/(n+m) for i in range(m)] for j in range(n)], n*m), 66 | np.random.normal(0., 0.08, n*m), 67 | 0.0006 68 | ) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/qcqp_sdo_relaxation.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: qcqp_sdo_relaxation.py 5 | # 6 | # Purpose: Demonstrate how to use SDP to solve 7 | # convex relaxation of a mixed-integer QCQP 8 | ## 9 | 10 | import math 11 | import sys 12 | import numpy 13 | import mosek 14 | from mosek.fusion import * 15 | 16 | # The relaxed SDP model 17 | def miqcqp_sdo_relaxation(n,P,q): 18 | M = Model() 19 | 20 | M.setLogHandler(sys.stdout) 21 | 22 | Z = M.variable("Z", Domain.inPSDCone(n+1)) 23 | X = Z.slice([0,0], [n,n]) 24 | x = Z.slice([0,n], [n,n+1]) 25 | 26 | M.constraint( Expr.sub(X.diag(), x), Domain.greaterThan(0.) ) 27 | M.constraint( Z.index(n,n), Domain.equalsTo(1.) ) 28 | 29 | M.objective( ObjectiveSense.Minimize, Expr.add( 30 | Expr.sum( Expr.mulElm( P, X ) ), 31 | Expr.mul( 2.0, Expr.dot(x, q) ) 32 | ) ) 33 | return M 34 | 35 | # A direct integer model for minimizing |Ax-b| 36 | def int_least_squares(n, A, b): 37 | M = Model() 38 | 39 | M.setLogHandler(sys.stdout) 40 | 41 | x = M.variable("x", n, Domain.integral(Domain.unbounded())) 42 | t = M.variable("t", 1, Domain.unbounded()) 43 | 44 | M.constraint( Expr.vstack(t, Expr.sub(Expr.mul(A, x), b)), Domain.inQCone() ) 45 | M.objective( ObjectiveSense.Minimize, t ) 46 | 47 | return M 48 | 49 | # problem dimensions 50 | n = 20 51 | m = 2*n 52 | 53 | # problem data 54 | A = numpy.reshape(numpy.random.normal(0., 1.0, n*m), (m,n)) 55 | c = numpy.random.uniform(0., 1.0, n) 56 | P = A.transpose().dot(A) 57 | q = - P.dot(c) 58 | b = A.dot(c) 59 | 60 | # solve the problems 61 | M = miqcqp_sdo_relaxation(n, P, q) 62 | Mint = int_least_squares(n, A, b) 63 | M.solve() 64 | Mint.solve() 65 | 66 | M.writeTask('M.ptf') 67 | M.writeTask('Mint.ptf') 68 | 69 | # rounded and optimal solution 70 | xRound = numpy.rint(M.getVariable("Z").slice([0,n], [n,n+1]).level()) 71 | xOpt = numpy.rint(Mint.getVariable("x").level()) 72 | 73 | print(M.getSolverDoubleInfo("optimizerTime"), Mint.getSolverDoubleInfo("optimizerTime")) 74 | print(numpy.linalg.norm(A.dot(xRound)-b), numpy.linalg.norm(A.dot(xOpt)-b)) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/lpt.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: lpt.py 5 | # 6 | # Purpose: Demonstrates how to solve the multi-processor 7 | # scheduling problem using the Fusion API. 8 | ## 9 | 10 | 11 | import sys 12 | import random 13 | from mosek.fusion import * 14 | 15 | 16 | def main(): 17 | #Parameters: 18 | n = 30 #Number of tasks 19 | m = 6 #Number of processors 20 | 21 | lb = 1. #Range of short task lengths 22 | ub = 5. 23 | 24 | sh = 0.8 #Proportion of short tasks 25 | n_short = int(n * sh) 26 | n_long = n - n_short 27 | 28 | random.seed(0) 29 | T = sorted([random.uniform(lb, ub) for i in range(n_short)] 30 | + [random.uniform(20 * lb, 20 * ub) for i in range(n_long)], reverse=True) 31 | 32 | print("# jobs(n) : ", n) 33 | print("# machine(m): ", m) 34 | 35 | with Model('Multi-processor scheduling') as M: 36 | 37 | x = M.variable('x', [m, n], Domain.binary()) 38 | t = M.variable('t', 1, Domain.unbounded()) 39 | 40 | M.constraint(Expr.sum(x, 0), Domain.equalsTo(1.)) 41 | M.constraint(Expr.sub(Var.repeat(t, m), Expr.mul(x, T)), 42 | Domain.greaterThan(0.)) 43 | 44 | M.objective(ObjectiveSense.Minimize, t) 45 | 46 | #LPT heuristic 47 | schedule = [0. for i in range(m)] 48 | init = [0. for i in range(n * m)] 49 | 50 | for i in range(n): 51 | mm = schedule.index(min(schedule)) 52 | schedule[mm] += T[i] 53 | init[n * mm + i] = 1. 54 | 55 | #Comment this line to switch off feeding in the initial LPT solution 56 | x.setLevel(init) 57 | 58 | M.setLogHandler(sys.stdout) 59 | M.setSolverParam("mioTolRelGap", .01) 60 | M.solve() 61 | 62 | print('initial solution:') 63 | for i in range(m): 64 | print('M', i, init[i * n:(i + 1) * n]) 65 | 66 | print('MOSEK solution:') 67 | for i in range(m): 68 | print('M', i, [y for y in x.slice([i, 0], [i + 1, n]).level()]) 69 | 70 | if __name__ == '__main__': 71 | main() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/reoptimization.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : reoptimization.py 5 | # 6 | # Purpose: Demonstrates how to solve a linear 7 | # optimization problem using the MOSEK API 8 | # and modify and re-optimize the problem. 9 | from mosek.fusion import * 10 | 11 | # Problem data 12 | c = [ 1.5, 2.5, 3.0 ] 13 | A = [ [2, 4, 3], 14 | [3, 2, 3], 15 | [2, 3, 2] ] 16 | b = [ 100000.0, 50000.0, 60000.0 ] 17 | numvar = len(c) 18 | numcon = len(b) 19 | 20 | # Create a model and input data 21 | with Model() as M: 22 | x = M.variable("x",numvar, Domain.greaterThan(0.0)) 23 | con = M.constraint(Expr.mul(A, x), Domain.lessThan(b)) 24 | M.objective(ObjectiveSense.Maximize, Expr.dot(c, x)) 25 | # Solve the problem 26 | M.solve() 27 | print("x = {}".format(x.level())) 28 | 29 | ############# Replace an element of the A matrix ############### 30 | x0 = x.index(0) 31 | con.index(0).update(Expr.mul(3.0, x0), x0) 32 | M.solve() 33 | print("x = {}".format(x.level())) 34 | 35 | ############## Add a new variable ################ 36 | # Create a variable and a compound view of all variables 37 | x3 = M.variable("y",Domain.greaterThan(0.0)) 38 | xNew = Var.vstack(x, x3) 39 | # Add to the exising constraint 40 | con.update(Expr.mul(x3, [4, 0, 1]), x3) 41 | # Change the objective to include x3 42 | M.objective(ObjectiveSense.Maximize, Expr.dot(c+[1.0], xNew)) 43 | M.solve() 44 | print("x = {}".format(xNew.level())) 45 | 46 | ############## Add a new constraint ################ 47 | con2 = M.constraint(Expr.dot(xNew, [1, 2, 1, 1]), Domain.lessThan(30000.0)) 48 | M.solve() 49 | print("x = {}".format(xNew.level())) 50 | 51 | ############## Change constraint bounds ################ 52 | cAll = Constraint.vstack(con, con2) 53 | # Change bounds by effectively updating fixed terms with the difference 54 | cAll.update([20000, 10000, 10000, 8000]) 55 | M.solve() 56 | print("x = {}".format(xNew.level())) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/java/mico1.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : mico1.java 5 | 6 | Purpose : Demonstrates how to solve a small mixed 7 | integer conic optimization problem. 8 | 9 | minimize x^2 + y^2 10 | subject to x >= e^y + 3.8 11 | x, y - integer 12 | */ 13 | 14 | package com.mosek.example; 15 | import mosek.*; 16 | 17 | public class mico1 { 18 | public static void main (String[] args) { 19 | try (Env env = new Env(); 20 | Task task = new Task(env, 0, 0)) { 21 | // Directs the log task stream to the user specified 22 | // method task_msg_obj.stream 23 | task.set_Stream( 24 | mosek.streamtype.log, 25 | new mosek.Stream() 26 | { public void stream(String msg) { System.out.print(msg); }}); 27 | 28 | task.appendvars(6); 29 | task.appendcons(3); 30 | task.putvarboundsliceconst(0, 6, mosek.boundkey.fr, -0.0, 0.0); 31 | 32 | // Integrality constraints 33 | task.putvartypelist(new int[]{1,2}, 34 | new mosek.variabletype[]{mosek.variabletype.type_int, mosek.variabletype.type_int}); 35 | 36 | // Set up the three auxiliary linear constraints 37 | task.putaijlist(new int[]{0,0,1,2,2}, 38 | new int[]{1,3,4,2,5}, 39 | new double[]{-1,1,1,1,-1}); 40 | task.putconboundslice(0, 3, 41 | new mosek.boundkey[]{mosek.boundkey.fx, mosek.boundkey.fx, mosek.boundkey.fx}, 42 | new double[]{-3.8, 1, 0}, new double[]{-3.8, 1, 0}); 43 | 44 | // Objective 45 | task.putobjsense(mosek.objsense.minimize); 46 | task.putcj(0, 1); 47 | 48 | // Conic part of the problem 49 | task.appendconeseq(mosek.conetype.quad, 0, 3, 0); 50 | task.appendconeseq(mosek.conetype.pexp, 0, 3, 3); 51 | 52 | // Optimize the task 53 | task.optimize(); 54 | task.solutionsummary(mosek.streamtype.msg); 55 | 56 | double[] xx = {0, 0}; 57 | task.getxxslice(mosek.soltype.itg, 1, 3, xx); 58 | System.out.println("x = " + xx[0] + " y = " + xx[1]); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/cqo1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: cqo1.py 5 | # 6 | # Purpose: Demonstrates how to solve the problem 7 | # 8 | # minimize y1 + y2 + y3 9 | # such that 10 | # x1 + x2 + 2.0 x3 = 1.0 11 | # x1,x2,x3 >= 0.0 12 | # and 13 | # (y1,x1,x2) in C_3, 14 | # (y2,y3,x3) in K_3 15 | # 16 | # where C_3 and K_3 are respectively the quadratic and 17 | # rotated quadratic cone of size 3 defined as 18 | # C_3 = { z1,z2,z3 : z1 >= sqrt(z2^2 + z3^2) } 19 | # K_3 = { z1,z2,z3 : 2 z1 z2 >= z3^2 } 20 | ## 21 | 22 | from mosek.fusion import * 23 | 24 | with Model('cqo1') as M: 25 | 26 | x = M.variable('x', 3, Domain.greaterThan(0.0)) 27 | y = M.variable('y', 3, Domain.unbounded()) 28 | 29 | # Create the aliases 30 | # z1 = [ y[0],x[0],x[1] ] 31 | # and z2 = [ y[1],y[2],x[2] ] 32 | z1 = Var.vstack(y.index(0), x.slice(0, 2)) 33 | z2 = Var.vstack(y.slice(1, 3), x.index(2)) 34 | 35 | # Create the constraint 36 | # x[0] + x[1] + 2.0 x[2] = 1.0 37 | M.constraint("lc", Expr.dot([1.0, 1.0, 2.0], x), Domain.equalsTo(1.0)) 38 | 39 | # Create the constraints 40 | # z1 belongs to C_3 41 | # z2 belongs to K_3 42 | # where C_3 and K_3 are respectively the quadratic and 43 | # rotated quadratic cone of size 3, i.e. 44 | # z1[0] >= sqrt(z1[1]^2 + z1[2]^2) 45 | # and 2.0 z2[0] z2[1] >= z2[2]^2 46 | qc1 = M.constraint("qc1", z1, Domain.inQCone()) 47 | qc2 = M.constraint("qc2", z2, Domain.inRotatedQCone()) 48 | 49 | # Set the objective function to (y[0] + y[1] + y[2]) 50 | M.objective("obj", ObjectiveSense.Minimize, Expr.sum(y)) 51 | 52 | # Solve the problem 53 | M.solve() 54 | M.writeTask('cqo1.opf') 55 | 56 | # Get the linear solution values 57 | solx = x.level() 58 | soly = y.level() 59 | print('x1,x2,x3 = %s' % str(solx)) 60 | print('y1,y2,y3 = %s' % str(soly)) 61 | 62 | # Get conic solution of qc1 63 | qc1lvl = qc1.level() 64 | qc1sn = qc1.dual() 65 | print('qc1 levels = %s' % str(qc1lvl)) 66 | print('qc1 dual conic var levels = %s' % str(qc1sn)) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/opt_server_async.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : opt_server_async.py 5 | # 6 | # Purpose : Demonstrates how to use MOSEK OptServer 7 | # to solve optimization problem asynchronously 8 | ## 9 | import mosek 10 | import sys 11 | import time 12 | 13 | def streamprinter(msg): 14 | sys.stdout.write(msg) 15 | sys.stdout.flush() 16 | 17 | if len(sys.argv) != 5: 18 | print("Missing argument, syntax is:") 19 | print(" opt-server-async inputfile host port numpolls") 20 | else: 21 | 22 | filename = sys.argv[1] 23 | host = sys.argv[2] 24 | port = sys.argv[3] 25 | numpolls = int(sys.argv[4]) 26 | token = None 27 | 28 | with mosek.Env() as env: 29 | 30 | with env.Task(0, 0) as task: 31 | 32 | print("reading task from file") 33 | task.readdata(filename) 34 | 35 | print("Solve the problem remotely (async)") 36 | token = task.asyncoptimize(host, port) 37 | 38 | print("Task token: %s" % token) 39 | 40 | with env.Task(0, 0) as task: 41 | 42 | task.readdata(filename) 43 | 44 | task.set_Stream(mosek.streamtype.log, streamprinter) 45 | 46 | i = 0 47 | 48 | while i < numpolls: 49 | 50 | time.sleep(0.1) 51 | 52 | print("poll %d..." % i) 53 | respavailable, res, trm = task.asyncpoll(host, 54 | port, 55 | token) 56 | 57 | print("done!") 58 | 59 | if respavailable: 60 | print("solution available!") 61 | 62 | respavailable, res, trm = task.asyncgetresult(host, 63 | port, 64 | token) 65 | 66 | task.solutionsummary(mosek.streamtype.log) 67 | break 68 | 69 | i = i + 1 70 | 71 | if i == numpolls: 72 | print("max number of polls reached, stopping host.") 73 | task.asyncstop(host, port, token) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/c/feasrepairex1.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 4 | 5 | File: feasrepairex1.c 6 | 7 | Purpose: To demonstrate how to use the MSK_primalrepair function to 8 | repair an infeasible problem. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | #include "mosek.h" 15 | 16 | static void MSKAPI printstr(void *handle, 17 | const char str[]) 18 | { 19 | fputs(str, stdout); 20 | } /* printstr */ 21 | 22 | static const char * feasrepair_lp = 23 | "minimize \n" 24 | " obj: - 10 x1 - 9 x2 \n" 25 | "st \n" 26 | " c1: + 7e-01 x1 + x2 <= 630 \n" 27 | " c2: + 5e-01 x1 + 8.333333333e-01 x2 <= 600 \n" 28 | " c3: + x1 + 6.6666667e-01 x2 <= 708 \n" 29 | " c4: + 1e-01 x1 + 2.5e-01 x2 <= 135 \n" 30 | "bounds \n" 31 | "x2 >= 650 \n" 32 | "end \n"; 33 | 34 | int main(int argc, const char *argv[]) 35 | { 36 | MSKenv_t env; 37 | MSKrescodee r, trmcode; 38 | MSKtask_t task; 39 | 40 | r = MSK_makeenv(&env, NULL); 41 | 42 | if (r == MSK_RES_OK) 43 | r = MSK_makeemptytask(env, &task); 44 | 45 | if (r == MSK_RES_OK) 46 | MSK_linkfunctotaskstream(task, MSK_STREAM_LOG, NULL, printstr); 47 | 48 | if (r == MSK_RES_OK) 49 | r = MSK_readlpstring(task,feasrepair_lp); /* Read problem from string */ 50 | 51 | if (r == MSK_RES_OK) 52 | r = MSK_putintparam(task, MSK_IPAR_LOG_FEAS_REPAIR, 3); 53 | 54 | if (r == MSK_RES_OK) 55 | { 56 | /* Weights are NULL implying all weights are 1. */ 57 | r = MSK_primalrepair(task, NULL, NULL, NULL, NULL); 58 | } 59 | 60 | if (r == MSK_RES_OK) 61 | { 62 | double sum_viol; 63 | 64 | r = MSK_getdouinf(task, MSK_DINF_PRIMAL_REPAIR_PENALTY_OBJ, &sum_viol); 65 | 66 | if (r == MSK_RES_OK) 67 | { 68 | printf("Minimized sum of violations = %e\n", sum_viol); 69 | 70 | r = MSK_optimizetrm(task, &trmcode); /* Optimize the repaired task. */ 71 | 72 | MSK_solutionsummary(task, MSK_STREAM_MSG); 73 | } 74 | } 75 | 76 | printf("Return code: %d\n", r); 77 | 78 | return (r); 79 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/total_variation.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: total_variation.cs 5 | // 6 | // Purpose: Demonstrates how to solve a total 7 | // variation problem using the Fusion API.using System; 8 | using System; 9 | using mosek.fusion; 10 | 11 | namespace mosek.fusion.example 12 | { 13 | public class total_variation 14 | { 15 | public static void Main(string[] args) 16 | { 17 | int ncols = 50; 18 | int nrows = 50; 19 | int seed = 0; 20 | double sigma = 1.0; 21 | int ncells = nrows * ncols; 22 | Random gen = new Random(seed); 23 | 24 | double[] f = new double[ncells]; 25 | 26 | //Random signal with Gaussian noise 27 | for (int i = 0; i < ncells; i++) 28 | { 29 | double xx = Math.Sqrt(-2.0 * Math.Log(gen.NextDouble())); 30 | double yy = Math.Sin(2.0 * Math.PI * gen.NextDouble()); 31 | f[i] = Math.Max(Math.Min(1.0, xx * yy) , .0); 32 | } 33 | 34 | 35 | Model M = new Model("TV"); 36 | try 37 | { 38 | Variable u = M.Variable(new int[] {nrows + 1, ncols + 1}, 39 | Domain.InRange(0.0, 1.0)); 40 | Variable t = M.Variable(new int[] {nrows, ncols}, Domain.Unbounded()); 41 | 42 | Variable ucore = u.Slice(new int[] {0, 0}, new int[] {nrows, ncols}); 43 | 44 | Expression deltax = Expr.Sub(u.Slice(new int[] {1, 0}, 45 | new int[] {nrows + 1, ncols}), 46 | ucore); 47 | Expression deltay = Expr.Sub(u.Slice(new int[] {0, 1}, 48 | new int[] {nrows, ncols + 1}), 49 | ucore); 50 | 51 | M.Constraint(Expr.Stack(2, t, deltax, deltay), Domain.InQCone().Axis(2)); 52 | 53 | Matrix mat_f = Matrix.Dense(nrows, ncols, f); 54 | M.Constraint(Expr.Vstack( sigma, Expr.Flatten( Expr.Sub(ucore, mat_f)) ), 55 | Domain.InQCone()); 56 | 57 | M.SetLogHandler(Console.Out); 58 | 59 | M.Objective(ObjectiveSense.Minimize, Expr.Sum(t)); 60 | 61 | M.Solve(); 62 | } 63 | finally 64 | { 65 | M.Dispose(); 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/sdo1.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : sdo1.R 5 | # 6 | # Purpose : To solve the mixed semidefinite and conic quadratic optimization problem 7 | # 8 | # minimize Tr [2, 1, 0; 1, 2, 1; 0, 1, 2]*X + x(1) 9 | # 10 | # subject to Tr [1, 0, 0; 0, 1, 0; 0, 0, 1]*X + x(1) = 1 11 | # Tr [1, 1, 1; 1, 1, 1; 1, 1, 1]*X + x(2) + x(3) = 0.5 12 | # X>=0, x(1) >= sqrt(x(2)^2 + x(3)^2) 13 | ## 14 | library("Rmosek") 15 | 16 | getbarvarMatrix <- function(barvar, bardim) 17 | { 18 | N <- as.integer(bardim) 19 | new("dspMatrix", x=barvar, uplo="L", Dim=c(N,N)) 20 | } 21 | 22 | sdo1 <- function() 23 | { 24 | # Specify the non-matrix variable part of the problem. 25 | prob <- list(sense="min") 26 | prob$c <- c(1, 0, 0) 27 | prob$A <- sparseMatrix(i=c(1, 2, 2), 28 | j=c(1, 2, 3), 29 | x=c(1, 1, 1), dims=c(2, 3)) 30 | prob$bc <- rbind(blc=c(1, 0.5), 31 | buc=c(1, 0.5)) 32 | prob$bx <- rbind(blx=rep(-Inf,3), 33 | bux=rep( Inf,3)) 34 | prob$cones <- cbind(list("QUAD", c(1, 2, 3))) 35 | 36 | # Specify semidefinite matrix variables (one 3x3 block) 37 | prob$bardim <- c(3) 38 | 39 | # Block triplet format specifying the lower triangular part 40 | # of the symmetric coefficient matrix 'barc': 41 | prob$barc$j <- c(1, 1, 1, 1, 1) 42 | prob$barc$k <- c(1, 2, 3, 2, 3) 43 | prob$barc$l <- c(1, 2, 3, 1, 2) 44 | prob$barc$v <- c(2, 2, 2, 1, 1) 45 | 46 | # Block triplet format specifying the lower triangular part 47 | # of the symmetric coefficient matrix 'barA': 48 | prob$barA$i <- c(1, 1, 1, 2, 2, 2, 2, 2, 2) 49 | prob$barA$j <- c(1, 1, 1, 1, 1, 1, 1, 1, 1) 50 | prob$barA$k <- c(1, 2, 3, 1, 2, 3, 2, 3, 3) 51 | prob$barA$l <- c(1, 2, 3, 1, 2, 3, 1, 1, 2) 52 | prob$barA$v <- c(1, 1, 1, 1, 1, 1, 1, 1, 1) 53 | 54 | # Solve the problem 55 | r <- mosek(prob) 56 | 57 | # Print matrix variable and return the solution 58 | stopifnot(identical(r$response$code, 0)) 59 | print( list(barx=getbarvarMatrix(r$sol$itr$barx[[1]], prob$bardim[1])) ) 60 | r$sol 61 | } 62 | 63 | sdo1() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/gp1.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: gp1.py 5 | # 6 | # Purpose: Demonstrates how to solve a simple Geometric Program (GP) 7 | # cast into conic form with exponential cones and log-sum-exp. 8 | # 9 | # Example from 10 | # https://gpkit.readthedocs.io/en/latest/examples.html#maximizing-the-volume-of-a-box 11 | # 12 | from numpy import log, exp, array 13 | from mosek.fusion import * 14 | import sys 15 | 16 | # Models log(sum(exp(Ax+b))) <= 0. 17 | # Each row of [A b] describes one of the exp-terms 18 | def logsumexp(M, A, x, b): 19 | k = int(A.shape[0]) 20 | u = M.variable(k) 21 | M.constraint(Expr.sum(u), Domain.equalsTo(1.0)) 22 | M.constraint(Expr.hstack(u, 23 | Expr.constTerm(k, 1.0), 24 | Expr.add(Expr.mul(A, x), b)), Domain.inPExpCone()) 25 | 26 | # maximize h*w*d 27 | # subjecto to 2*(h*w + h*d) <= Awall 28 | # w*d <= Afloor 29 | # alpha <= h/w <= beta 30 | # gamma <= d/w <= delta 31 | # 32 | # Variable substitutions: h = exp(x), w = exp(y), d = exp(z). 33 | # 34 | # maximize x+y+z 35 | # subject log( exp(x+y+log(2/Awall)) + exp(x+z+log(2/Awall)) ) <= 0 36 | # y+z <= log(Afloor) 37 | # log( alpha ) <= x-y <= log( beta ) 38 | # log( gamma ) <= z-y <= log( delta ) 39 | def max_volume_box(Aw, Af, alpha, beta, gamma, delta): 40 | with Model('max_vol_box') as M: 41 | xyz = M.variable(3) 42 | M.objective('Objective', ObjectiveSense.Maximize, Expr.sum(xyz)) 43 | 44 | logsumexp(M, array([[1,1,0],[1,0,1]]), xyz, array([log(2.0/Aw), log(2.0/Aw)])) 45 | 46 | M.constraint(Expr.dot([0, 1, 1], xyz), Domain.lessThan(log(Af))) 47 | M.constraint(Expr.dot([1,-1, 0], xyz), Domain.inRange(log(alpha),log(beta))) 48 | M.constraint(Expr.dot([0,-1, 1], xyz), Domain.inRange(log(gamma),log(delta))) 49 | 50 | M.setLogHandler(sys.stdout) 51 | M.solve() 52 | 53 | return exp(xyz.level()) 54 | 55 | Aw, Af, alpha, beta, gamma, delta = 200.0, 50.0, 2.0, 10.0, 2.0, 10.0 56 | h,w,d = max_volume_box(Aw, Af, alpha, beta, gamma, delta) 57 | print("h={0:.3f}, w={1:.3f}, d={2:.3f}".format(h, w, d)) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/java/breaksolver.java: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: breaksolver.java 5 | // 6 | // Purpose: Show how to break a long-running task. 7 | // 8 | // Requires a parameter defining a timeout in seconds. 9 | // 10 | 11 | 12 | package com.mosek.fusion.examples; 13 | import mosek.fusion.*; 14 | import java.util.Random; 15 | 16 | public class breaksolver { 17 | private static void nshuffle(Random R, int[] a, int n) { 18 | for (int i = 0; i < n; ++i) { 19 | int idx = (int)(R.nextDouble() * (a.length - i)) + i; 20 | int tmp = a[i]; a[i] = a[idx]; a[idx] = tmp; 21 | } 22 | } 23 | 24 | public static void main(String[] args) 25 | throws java.lang.InterruptedException, SolutionError { 26 | long timeout = 5; 27 | 28 | int n = 200; // number of binary variables 29 | int m = n / 5; // number of constraints 30 | int p = n / 5; // Each constraint picks p variables and requires that half of them are 1 31 | Random R = new Random(1234); 32 | 33 | System.out.println("Build problem..."); 34 | try (Model M = new Model("SolveBinary")) { 35 | M.setLogHandler(new java.io.PrintWriter(System.out)); 36 | 37 | Variable x = M.variable("x", n, Domain.binary()); 38 | M.objective(ObjectiveSense.Minimize, Expr.sum(x)); 39 | 40 | int[] idxs = new int[n]; 41 | for (int i = 0; i < n; ++i) 42 | idxs[i] = i; 43 | 44 | for (int i = 0; i < m; ++i) { 45 | nshuffle(R, idxs, p); 46 | M.constraint(Expr.sum(x.pick(java.util.Arrays.copyOf(idxs, p))), 47 | Domain.equalsTo(p / 2)); 48 | } 49 | 50 | System.out.println("Start thread..."); 51 | Thread T = new Thread() { public void run() { M.solve(); } }; 52 | T.start(); 53 | 54 | long T0 = System.currentTimeMillis(); 55 | while (true) { 56 | if (System.currentTimeMillis() - T0 > timeout * 1000) { 57 | System.out.println("Solver terminated due to timeout!"); 58 | M.breakSolver(); 59 | T.join(); 60 | break; 61 | } 62 | if (! T.isAlive()) { 63 | System.out.println("Solver terminated before anything happened!"); 64 | T.join(); 65 | break; 66 | } 67 | } 68 | } finally { 69 | System.out.println("End."); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/rmosek/portfolio_2_frontier.R: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : portfolio_2_frontier.R 5 | # 6 | # Purpose : To implements a basic portfolio optimization model. 7 | # Computes points on the efficient frontier. 8 | ## 9 | library("Rmosek") 10 | 11 | EfficientFrontier <- function( 12 | n, # Number of assets 13 | mu, # An n-dimmensional vector of expected returns 14 | GT, # A matrix with n columns so (GT')*GT = covariance matrix 15 | x0, # Initial holdings 16 | w, # Initial cash holding 17 | alphas) # List of risk penalties (we maximize expected return - alpha * variance) 18 | { 19 | prob <- list(sense="max") 20 | prob$A <- cbind(Matrix(1.0, ncol=n), 0.0) 21 | prob$bc <- rbind(blc=w+sum(x0), 22 | buc=w+sum(x0)) 23 | prob$bx <- rbind(blx=c(rep(0.0,n), -Inf), 24 | bux=rep(Inf,n+1)) 25 | 26 | # Specify the affine conic constraints. 27 | NUMCONES <- 1 28 | prob$F <- rbind( 29 | cbind(Matrix(0.0,ncol=n), 1.0), 30 | rep(0, n+1), 31 | cbind(GT , 0.0) 32 | ) 33 | prob$g <- c(0, 0.5, rep(0, n)) 34 | prob$cones <- matrix(list(), nrow=3, ncol=NUMCONES) 35 | rownames(prob$cones) <- c("type","dim","conepar") 36 | 37 | prob$cones[-3,1] <- list("RQUAD", n+2) 38 | 39 | frontier <- matrix(NaN, ncol=3, nrow=length(alphas)) 40 | colnames(frontier) <- c("alpha","exp.ret.","variance") 41 | 42 | for (i in seq_along(alphas)) 43 | { 44 | prob$c <- c(mu, -alphas[i]) 45 | 46 | r <- mosek(prob, list(verbose=1)) 47 | stopifnot(identical(r$response$code, 0)) 48 | 49 | x <- r$sol$itr$xx[1:n] 50 | gamma <- r$sol$itr$xx[n+1] 51 | 52 | frontier[i,] <- c(alphas[i], drop(mu%*%x), gamma) 53 | } 54 | 55 | frontier 56 | } 57 | 58 | # Example of input 59 | n <- 3; 60 | w <- 1.0; 61 | mu <- c(0.1073, 0.0737, 0.0627) 62 | x0 <- c(0.0, 0.0, 0.0) 63 | alphas <- c(0.0, 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5) 64 | GT <- rbind(c(0.1667, 0.0232, 0.0013 ), 65 | c(0.0000, 0.1033, -0.0022), 66 | c(0.0000, 0.0000, 0.0338 )) 67 | 68 | frontier <- EfficientFrontier(n,mu,GT,x0,w,alphas) 69 | print(frontier) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/facility_location.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: facility_location.py 5 | # 6 | # Purpose: Demonstrates a small one-facility location problem. 7 | # 8 | # Given 10 customers placed in a grid we wish to place a facility 9 | # somewhere so that the total sum of distances to customers is 10 | # minimized. 11 | # 12 | # The problem is formulated as a conic optimization problem as follows. 13 | # Let f=(fx,fy) be the (unknown) location of the facility, and let 14 | # c_i=(cx_i,cy_i) be the (known) customer locations; then we wish to 15 | # minimize 16 | # sum_i || f - c_i || 17 | # where 18 | # ||.|| 19 | # denotes the euclidian norm. 20 | # This is formulated as 21 | # 22 | # minimize sum(d_i) 23 | # such that d_i ^ 2 > tx_i ^ 2 + ty_i ^ 2, for all i (a.k.a. (d_i,tx_i,ty_i) in C^3_r) 24 | # tx_i = cx_i - fx, for all i 25 | # ty_i = cy_i - fy, for all i 26 | # d_i > 0, for all i 27 | ## 28 | import sys 29 | from mosek.fusion import * 30 | 31 | # Customer locations 32 | customerloc = Matrix.dense([[12.0, 2.0], 33 | [15.0, 13.0], 34 | [10.0, 8.0], 35 | [0.0, 10.0], 36 | [6.0, 13.0], 37 | [5.0, 8.0], 38 | [10.0, 12.0], 39 | [4.0, 6.0], 40 | [5.0, 2.0], 41 | [1.0, 10.0]]) 42 | N = customerloc.numRows() 43 | 44 | with Model('FacilityLocation') as M: 45 | # Variable holding the facility location 46 | f = M.variable("facility", Set.make(1, 2), Domain.unbounded()) 47 | # Variable defining the euclidian distances to each customer 48 | d = M.variable("dist", Set.make(N, 1), Domain.greaterThan(0.0)) 49 | # Variable defining the x and y differences to each customer 50 | t = M.variable("t", Set.make(N, 2), Domain.unbounded()) 51 | M.constraint('dist measure', Var.hstack(d, t), Domain.inQCone()) 52 | 53 | fxy = Var.repeat(f, N) 54 | 55 | M.constraint("xy diff", Expr.add(t, fxy), Domain.equalsTo(customerloc)) 56 | 57 | M.objective("total_dist", ObjectiveSense.Minimize, Expr.sum(d)) 58 | 59 | M.solve() 60 | M.writeTask("facility_location.task") 61 | print('Facility location =', f.level()) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/dotnet/mico1.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : mico1.cs 5 | 6 | Purpose : Demonstrates how to solve a small mixed 7 | integer conic optimization problem. 8 | 9 | minimize x^2 + y^2 10 | subject to x >= e^y + 3.8 11 | x, y - integer 12 | */ 13 | using System; 14 | 15 | namespace mosek.example 16 | { 17 | public class MsgClass : mosek.Stream 18 | { 19 | public MsgClass () {} 20 | public override void streamCB (string msg) 21 | { 22 | Console.Write ("{0}", msg); 23 | } 24 | } 25 | 26 | public class mico1 27 | { 28 | public static void Main () 29 | { 30 | mosek.Env env = new mosek.Env (); 31 | mosek.Task task = new mosek.Task(env, 0, 0); 32 | 33 | // Directs the log task stream to the user specified 34 | // method task_msg_obj.streamCB 35 | MsgClass task_msg_obj = new MsgClass (); 36 | task.set_Stream (mosek.streamtype.log, task_msg_obj); 37 | 38 | task.appendvars(6); 39 | task.appendcons(3); 40 | task.putvarboundsliceconst(0, 6, mosek.boundkey.fr, -0.0, 0.0); 41 | 42 | // Integrality constraints 43 | task.putvartypelist(new int[]{1,2}, 44 | new mosek.variabletype[]{mosek.variabletype.type_int, mosek.variabletype.type_int}); 45 | 46 | // Set up the three auxiliary linear constraints 47 | task.putaijlist(new int[]{0,0,1,2,2}, 48 | new int[]{1,3,4,2,5}, 49 | new double[]{-1,1,1,1,-1}); 50 | task.putconboundslice(0, 3, 51 | new mosek.boundkey[]{mosek.boundkey.fx, mosek.boundkey.fx, mosek.boundkey.fx}, 52 | new double[]{-3.8, 1, 0}, new double[]{-3.8, 1, 0}); 53 | 54 | // Objective 55 | task.putobjsense(mosek.objsense.minimize); 56 | task.putcj(0, 1); 57 | 58 | // Conic part of the problem 59 | task.appendconeseq(mosek.conetype.quad, 0, 3, 0); 60 | task.appendconeseq(mosek.conetype.pexp, 0, 3, 3); 61 | 62 | // Optimize the task 63 | task.optimize(); 64 | task.solutionsummary(mosek.streamtype.msg); 65 | 66 | double[] xx = {0, 0}; 67 | task.getxxslice(mosek.soltype.itg, 1, 3, xx); 68 | Console.WriteLine ("x = {0}, y = {1}", xx[0], xx[1]); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/java/parameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File : parameters.java 5 | 6 | Purpose : Demonstrates a very simple example about how to get/set 7 | parameters with MOSEK Java API 8 | */ 9 | 10 | package com.mosek.example; 11 | import mosek.*; 12 | 13 | public class parameters { 14 | 15 | public static void main (String[] args) { 16 | try { 17 | mosek.Env env = new Env(); 18 | mosek.Task task = new Task(env, 0, 0); 19 | 20 | System.out.println("Test MOSEK parameter get/set functions"); 21 | 22 | // Set log level (integer parameter) 23 | task.putintparam(mosek.iparam.log, 1); 24 | // Select interior-point optimizer... (integer parameter) 25 | task.putintparam(mosek.iparam.optimizer, mosek.optimizertype.intpnt.value); 26 | // ... without basis identification (integer parameter) 27 | task.putintparam(mosek.iparam.intpnt_basis, mosek.basindtype.never.value); 28 | // Set relative gap tolerance (double parameter) 29 | task.putdouparam(mosek.dparam.intpnt_co_tol_rel_gap, 1.0e-7); 30 | 31 | // The same using explicit string names 32 | task.putparam ("MSK_DPAR_INTPNT_CO_TOL_REL_GAP", "1.0e-7"); 33 | task.putnadouparam("MSK_DPAR_INTPNT_CO_TOL_REL_GAP", 1.0e-7 ); 34 | 35 | // Incorrect value 36 | try { 37 | task.putdouparam(mosek.dparam.intpnt_co_tol_rel_gap, -1.0); 38 | } 39 | catch (mosek.Error e) { 40 | System.out.println("Wrong parameter value"); 41 | } 42 | 43 | 44 | double param = task.getdouparam(mosek.dparam.intpnt_co_tol_rel_gap); 45 | System.out.println("Current value for parameter intpnt_co_tol_rel_gap = " + param); 46 | 47 | /* Define and solve an optimization problem here */ 48 | /* task.optimize() */ 49 | /* After optimization: */ 50 | 51 | System.out.println("Get MOSEK information items"); 52 | 53 | double tm = task.getdouinf(mosek.dinfitem.optimizer_time); 54 | int iter = task.getintinf(mosek.iinfitem.intpnt_iter); 55 | 56 | System.out.println("Time: " + tm); 57 | System.out.println("Iterations: " + iter); 58 | } catch (mosek.Exception e) { 59 | System.out.println ("An error/warning was encountered"); 60 | System.out.println (e.toString()); 61 | throw e; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/dotnet/parameters.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: parameters.cs 5 | 6 | Purpose: Demonstrates a very simple example about how to get/set 7 | parameters with MOSEK .NET API 8 | 9 | */ 10 | 11 | using System; 12 | 13 | namespace mosek.example 14 | { 15 | public class parameters 16 | { 17 | public static void Main() 18 | { 19 | using (mosek.Env env = new mosek.Env()) 20 | { 21 | using (mosek.Task task = new mosek.Task(env, 0, 0)) 22 | { 23 | Console.WriteLine("Test MOSEK parameter get/set functions"); 24 | 25 | // Set log level (integer parameter) 26 | task.putintparam(mosek.iparam.log, 1); 27 | // Select interior-point optimizer... (integer parameter) 28 | task.putintparam(mosek.iparam.optimizer, mosek.optimizertype.intpnt); 29 | // ... without basis identification (integer parameter) 30 | task.putintparam(mosek.iparam.intpnt_basis, mosek.basindtype.never); 31 | // Set relative gap tolerance (double parameter) 32 | task.putdouparam(mosek.dparam.intpnt_co_tol_rel_gap, 1.0e-7); 33 | 34 | // The same using explicit string names 35 | task.putparam ("MSK_DPAR_INTPNT_CO_TOL_REL_GAP", "1.0e-7"); 36 | task.putnadouparam("MSK_DPAR_INTPNT_CO_TOL_REL_GAP", 1.0e-7 ); 37 | 38 | // Incorrect value 39 | try 40 | { 41 | task.putdouparam(mosek.dparam.intpnt_co_tol_rel_gap, -1.0); 42 | } 43 | catch (mosek.Error) 44 | { 45 | Console.WriteLine("Wrong parameter value"); 46 | } 47 | 48 | 49 | double param = task.getdouparam(mosek.dparam.intpnt_co_tol_rel_gap); 50 | Console.WriteLine("Current value for parameter intpnt_co_tol_rel_gap = " + param); 51 | 52 | /* Define and solve an optimization problem here */ 53 | /* task.optimize() */ 54 | /* After optimization: */ 55 | 56 | Console.WriteLine("Get MOSEK information items"); 57 | 58 | double tm = task.getdouinf(mosek.dinfitem.optimizer_time); 59 | int iter = task.getintinf(mosek.iinfitem.intpnt_iter); 60 | 61 | Console.WriteLine("Time: " + tm); 62 | Console.WriteLine("Iterations: " + iter); 63 | } 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/c/parameters.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: parameters.c 5 | 6 | Purpose: Demonstrates a very simple example about how to get/set 7 | parameters with MOSEK C API 8 | */ 9 | 10 | #include "mosek.h" 11 | #include "stdio.h" 12 | 13 | int main() 14 | { 15 | 16 | MSKenv_t env = NULL; 17 | MSKtask_t task = NULL; 18 | MSKrescodee res, trmcode; 19 | 20 | double param = 0.0; 21 | double tm; 22 | MSKint32t iter; 23 | 24 | /* Create an environment */ 25 | res = MSK_makeenv(&env, NULL); 26 | 27 | if (res == MSK_RES_OK) 28 | { 29 | /* Create a task */ 30 | res = MSK_maketask(env, 0, 0, &task); 31 | 32 | if (res == MSK_RES_OK) 33 | { 34 | printf("Test MOSEK parameter get/set functions\n"); 35 | 36 | // Set log level (integer parameter) 37 | res = MSK_putintparam(task, MSK_IPAR_LOG, 1); 38 | // Select interior-point optimizer... (integer parameter) 39 | res = MSK_putintparam(task, MSK_IPAR_OPTIMIZER, MSK_OPTIMIZER_INTPNT); 40 | // ... without basis identification (integer parameter) 41 | res = MSK_putintparam(task, MSK_IPAR_INTPNT_BASIS, MSK_BI_NEVER); 42 | // Set relative gap tolerance (double parameter) 43 | res = MSK_putdouparam(task, MSK_DPAR_INTPNT_CO_TOL_REL_GAP, 1.0e-7); 44 | 45 | // The same using explicit string names 46 | res = MSK_putparam(task, "MSK_DPAR_INTPNT_CO_TOL_REL_GAP", "1.0e-7"); 47 | res = MSK_putnadouparam(task, "MSK_DPAR_INTPNT_CO_TOL_REL_GAP", 1.0e-7); 48 | 49 | // Incorrect value 50 | res = MSK_putdouparam(task, MSK_DPAR_INTPNT_CO_TOL_REL_GAP, -1.0); 51 | if (res != MSK_RES_OK) 52 | printf("Wrong parameter value\n"); 53 | 54 | res = MSK_getdouparam(task, MSK_DPAR_INTPNT_CO_TOL_REL_GAP, ¶m); 55 | printf("Current value for parameter MSK_DPAR_INTPNT_CO_TOL_REL_GAP = %e\n", param); 56 | 57 | /* Define and solve an optimization problem here */ 58 | /* MSK_optimizetrm(task, &trmcode) */ 59 | /* After optimization: */ 60 | 61 | printf("Get MOSEK information items\n"); 62 | 63 | res = MSK_getdouinf(task, MSK_DINF_OPTIMIZER_TIME, &tm); 64 | res = MSK_getintinf(task, MSK_IINF_INTPNT_ITER, &iter); 65 | 66 | printf("Time: %f\nIterations: %d\n", tm, iter); 67 | 68 | MSK_deletetask(&task); 69 | } 70 | MSK_deleteenv(&env); 71 | } 72 | return 0; 73 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/c/parallel.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | 4 | File: parallel.cc 5 | 6 | Purpose: Demonstrates parallel optimization 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /** Runs a single task */ 14 | void runTask(int num, 15 | MSKtask_t task, 16 | MSKrescodee *res, 17 | MSKrescodee *trm) 18 | { 19 | *res = MSK_optimizetrm(task, trm); 20 | } 21 | 22 | /** Takes a list of tasks and optimizes then in parallel. The 23 | response code and termination code from each optimization is 24 | stored in ``res`` and ``trm``. 25 | */ 26 | void paropt(int n, 27 | MSKtask_t *tasks, 28 | MSKrescodee *res, 29 | MSKrescodee *trm) 30 | { 31 | int i; 32 | std::thread * jobs = new std::thread[n]; 33 | 34 | // Initialize 35 | for(i = 0; i < n; ++i) { 36 | res[i] = trm[i] = MSK_RES_ERR_UNKNOWN; 37 | jobs[i] = std::thread(runTask, i, tasks[i], &(res[i]), &(trm[i])); 38 | } 39 | 40 | // Join all threads 41 | for(i = 0; i < n; ++i) jobs[i].join(); 42 | delete[] jobs; 43 | } 44 | 45 | /** Example of how to use ``paropt``. 46 | Optimizes tasks whose names were read from command line. 47 | */ 48 | int main(int argc, char **argv) 49 | { 50 | MSKenv_t env; 51 | int n = argc - 1; 52 | MSKtask_t *tasks = new MSKtask_t[n]; 53 | MSKrescodee *res = new MSKrescodee[n]; 54 | MSKrescodee *trm = new MSKrescodee[n]; 55 | 56 | MSK_makeenv(&env, NULL); 57 | 58 | for (int i = 0; i < n; i++) { 59 | MSK_makeemptytask(env, &(tasks[i])); 60 | MSK_readdata(tasks[i], argv[i+1]); 61 | // Each task will be single-threaded 62 | MSK_putintparam(tasks[i], MSK_IPAR_INTPNT_MULTI_THREAD, MSK_OFF); 63 | } 64 | 65 | paropt(n, tasks, res, trm); 66 | 67 | for(int i = 0; i < n; i++) { 68 | double obj, tm; 69 | MSK_getdouinf(tasks[i], MSK_DINF_INTPNT_PRIMAL_OBJ, &obj); 70 | MSK_getdouinf(tasks[i], MSK_DINF_OPTIMIZER_TIME, &tm); 71 | 72 | printf("Task %d res %d trm %d obj_val %.5f time %.5f\n", 73 | i, 74 | res[i], 75 | trm[i], 76 | obj, 77 | tm); 78 | } 79 | 80 | for(int i = 0; i < n; i++) 81 | MSK_deletetask(&(tasks[i])); 82 | delete[] tasks; 83 | delete[] res; 84 | delete[] trm; 85 | MSK_deleteenv(&env); 86 | return 0; 87 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/total_variation.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: total_variation.cc 5 | // 6 | // Purpose: Demonstrates how to solve a total 7 | // variation problem using the Fusion API. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "monty.h" 14 | #include "fusion.h" 15 | 16 | using namespace mosek::fusion; 17 | using namespace monty; 18 | 19 | int main(int argc, char ** argv) 20 | { 21 | int nrows = 50; 22 | int ncols = 50; 23 | int ncells = nrows * ncols; 24 | int seed = 0; 25 | double sigma = 1.0; 26 | 27 | std::uniform_real_distribution udistr(0., 1.); 28 | std::normal_distribution ndistr(0., 1.); 29 | std::mt19937 engine(seed); 30 | 31 | auto f = std::shared_ptr >(new ndarray(ncells) ); 32 | 33 | //Random signal with Gaussian noise 34 | for (int i = 0; i < ncells; i++) 35 | (*f)[i] = std::max(0., std::min(1.0, udistr(engine) + ndistr(engine) ) ) ; 36 | 37 | Model::t M = new Model("TV"); auto _M = finally([&]() { M->dispose(); }); 38 | 39 | auto u = M->variable(new_array_ptr({nrows + 1, ncells + 1}), Domain::inRange(0., 1.)); 40 | auto t = M->variable(new_array_ptr({nrows, ncols}), Domain::unbounded()); 41 | auto ucore = u->slice(new_array_ptr({0, 0}), new_array_ptr({nrows, ncols})); 42 | 43 | auto deltax = Expr::sub( u->slice( new_array_ptr({1, 0}), new_array_ptr({nrows + 1, ncols}) ), ucore); 44 | auto deltay = Expr::sub( u->slice( new_array_ptr({0, 1}) , new_array_ptr({nrows, ncols + 1}) ), ucore); 45 | 46 | M->constraint( Expr::stack(2., t, deltax, deltay), Domain::inQCone()->axis(2) ); 47 | 48 | M->constraint( Expr::vstack(sigma, Expr::flatten( Expr::sub( Matrix::dense(nrows, ncols, f), ucore ) ) ), Domain::inQCone() ); 49 | 50 | M->objective( ObjectiveSense::Minimize, Expr::sum(t) ); 51 | M->setLogHandler([](const std::string & msg) { std::cout << msg << std::flush; } ); 52 | M->solve(); 53 | 54 | std::vector deltas(ncells); 55 | auto uu = *(u->level()); 56 | for (int i = 0; i < ncells; i++) 57 | deltas[i] = std::abs( uu[i] - (*f)[i]); 58 | 59 | std::cerr << "max deltas= " << *max_element(deltas.begin(), deltas.end()) << std::endl; 60 | std::cerr << "min deltas= " << *min_element(deltas.begin(), deltas.end()) << std::endl; 61 | 62 | return 0; 63 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/primal_svm.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: primal_svm.cs 5 | // 6 | // Purpose: Implements a simple soft-margin SVM 7 | // using the Fusion API. 8 | 9 | using System; 10 | using System.Collections.Generic; 11 | 12 | using mosek.fusion; 13 | 14 | namespace mosek.fusion.example 15 | { 16 | public class primal_svm 17 | { 18 | public static void Main(string[] args) 19 | { 20 | int nc = 10; 21 | int m = 50; 22 | int n = 3; 23 | int seed = 1; 24 | double variance = 1.0; 25 | double mean = 1.0; 26 | 27 | Random gen = new Random(seed); 28 | 29 | int nump = gen.Next(m); 30 | 31 | double [] y = new double[m]; 32 | 33 | for (int i = 0; i < nump; i++) y[i] = 1.0; 34 | for (int i = nump; i < m; i++) y[i] = -1.0; 35 | 36 | double [,] X = new double[m, n]; 37 | 38 | for (int i = 0; i < nump; i++) 39 | for (int j = 0; j < n; j++) { 40 | double xx = Math.Sqrt( -2.0 * Math.Log(gen.NextDouble()) ); 41 | double yy = Math.Sin( 2.0 * Math.PI * gen.NextDouble() ); 42 | X[i, j] = (xx * yy) * variance + mean; 43 | } 44 | Model M = new Model("Primal SVM"); 45 | try { 46 | Console.WriteLine("Number of data : {0}\n", m); 47 | Console.WriteLine("Number of features: {0}\n", n); 48 | 49 | Variable w = M.Variable( n, Domain.Unbounded() ); 50 | Variable t = M.Variable( 1, Domain.Unbounded() ); 51 | Variable b = M.Variable( 1, Domain.Unbounded() ); 52 | Variable xi = M.Variable( m, Domain.GreaterThan(0.0) ); 53 | 54 | M.Constraint( Expr.Add(Expr.MulElm( y, Expr.Sub( Expr.Mul(X, w), Var.Repeat(b, m) ) ), xi ), 55 | Domain.GreaterThan( 1.0 ) ); 56 | M.Constraint( Expr.Vstack(1.0, t, w) , Domain.InRotatedQCone()); 57 | 58 | Console.WriteLine(" c | b | w"); 59 | for (int i = 0; i < nc; i++) { 60 | double c = 500.0 * i; 61 | M.Objective(ObjectiveSense.Minimize, Expr.Add( t, Expr.Mul(c, Expr.Sum(xi) ) ) ); 62 | M.Solve(); 63 | 64 | Console.Write("{0} | {1} |", c, b.Level()[0] ); 65 | for (int j = 0; j < n; j++) 66 | Console.Write(" {0}", w.Level()[j] ); 67 | Console.WriteLine(); 68 | } 69 | } 70 | finally { 71 | M.Dispose(); 72 | } 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/dotnet/breaksolver.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: breaksolver.cs 5 | // 6 | // Purpose: Show how to break a long-running task. 7 | // 8 | // Requires a parameter defining a timeout in seconds. 9 | // 10 | 11 | 12 | using System; 13 | using System.Threading; 14 | using mosek.fusion; 15 | using System.Diagnostics; 16 | 17 | namespace mosek.fusion.example 18 | { 19 | public class breaksolver 20 | { 21 | private static void nshuffle(Random R, int[] a, int n) 22 | { 23 | for (int i = 0; i < n; ++i) 24 | { 25 | int idx = R.Next(i, a.Length); 26 | int tmp = a[i]; a[i] = a[idx]; a[idx] = tmp; 27 | } 28 | } 29 | 30 | public static void Main(string[] args) 31 | { 32 | long timeout = 5; 33 | 34 | int n = 200; // number of binary variables 35 | int m = n / 5; // number of constraints 36 | int p = n / 5; // Each constraint picks p variables and requires that half of them are 1 37 | Random R = new Random(1234); 38 | using (Model M = new Model("SolveBinary")) 39 | { 40 | M.SetLogHandler(System.Console.Out); 41 | 42 | //Variable x = M.Variable("x", n, Domain.InRange(0,1)); 43 | Variable x = M.Variable("x", n, Domain.Binary()); 44 | M.Objective(ObjectiveSense.Minimize, Expr.Sum(x)); 45 | //M.SetSolverParam("numThreads",1); 46 | 47 | int[] idxs = new int[n]; for (int i = 0; i < n; ++i) idxs[i] = i; 48 | int[] cidxs = new int[p]; 49 | 50 | for (var i = 0; i < m; ++i) 51 | { 52 | nshuffle(R, idxs, p); 53 | Array.Copy(idxs, cidxs, p); 54 | M.Constraint(Expr.Sum(x.Pick(cidxs)), Domain.EqualsTo(p / 2)); 55 | } 56 | 57 | var T = new Thread(new ThreadStart(M.Solve)); 58 | T.Start(); 59 | 60 | Stopwatch w = new Stopwatch(); w.Start(); 61 | while (true) 62 | { 63 | if (w.ElapsedMilliseconds > timeout * 1000) 64 | { 65 | Console.WriteLine("Solver terminated due to timeout!"); 66 | M.BreakSolver(); 67 | T.Join(); 68 | break; 69 | } 70 | if (! T.IsAlive) { 71 | Console.WriteLine("Solver terminated before anything happened!"); 72 | T.Join(); 73 | break; 74 | } 75 | } 76 | 77 | Console.WriteLine("End."); 78 | } 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/primal_svm.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: primal_svm.cc 5 | // 6 | // Purpose: Implements a simple soft-margin SVM 7 | // using the Fusion API. 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "fusion.h" 16 | 17 | using namespace mosek::fusion; 18 | using namespace monty; 19 | 20 | int main(int argc, char ** argv) 21 | { 22 | int m = 50 ; 23 | int n = 3; 24 | int nc = 10; 25 | 26 | int nump = m / 2; 27 | int numm = m - nump; 28 | 29 | auto y = new_array_ptr (m); 30 | std::fill( y->begin(), y->begin() + nump, 1.); 31 | std::fill( y->begin() + nump, y->end(), -1.); 32 | 33 | double mean = 1.; 34 | double var = 1.; 35 | 36 | auto X = std::shared_ptr< ndarray > ( new ndarray ( shape_t<2>(m, n) ) ); 37 | 38 | std::mt19937 e2(0); 39 | 40 | for (int i = 0; i < nump; i++) 41 | { 42 | auto ram = std::bind(std::normal_distribution<>(mean, var), e2); 43 | for ( int j = 0; j < n; j++) 44 | (*X)(i, j) = ram(); 45 | } 46 | 47 | std::cout << "Number of data : " << m << std::endl; 48 | std::cout << "Number of features: " << n << std::endl; 49 | Model::t M = new Model("primal SVM"); auto _M = finally([&]() { M->dispose(); }); 50 | 51 | Variable::t w = M->variable( n, Domain::unbounded()); 52 | Variable::t t = M->variable( 1, Domain::unbounded()); 53 | Variable::t b = M->variable( 1, Domain::unbounded()); 54 | Variable::t xi = M->variable( m, Domain::greaterThan(0.)); 55 | 56 | auto ex = Expr::sub( Expr::mul(X, w), Var::repeat(b, m) ); 57 | M->constraint( Expr::add(Expr::mulElm( y, ex ), xi ) , Domain::greaterThan( 1. ) ); 58 | 59 | M->constraint( Expr::vstack(1., t, w) , Domain::inRotatedQCone() ); 60 | 61 | std::cout << " c | b | w\n"; 62 | for (int i = 0; i < nc; i++) 63 | { 64 | double c = 500.0 * i; 65 | M->objective( ObjectiveSense::Minimize, Expr::add( t, Expr::mul(c, Expr::sum(xi) ) ) ); 66 | M->solve(); 67 | 68 | try 69 | { 70 | std::cout << std::setw(6) << c << " | " << std::setw(8) << (*(b->level())) [0] << " | "; 71 | std::cout.width(8); 72 | auto wlev = w->level(); 73 | std::copy( wlev->begin(), wlev->end() , std::ostream_iterator(std::cout, " ") ); 74 | std::cout << "\n"; 75 | } 76 | catch (...) {} 77 | 78 | } 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/python/sudoku.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File: sudoku.py 5 | # 6 | # Purpose: A MILP-based SUDOKU solver 7 | # 8 | # 9 | 10 | import sys 11 | import mosek 12 | from mosek.fusion import * 13 | import numpy as npy 14 | 15 | 16 | def print_solution(m, x): 17 | n = m * m 18 | print("\n") 19 | for i in range(n): 20 | ss = "" 21 | for j in range(n): 22 | if j % m == 0: 23 | ss = ss + " |" 24 | 25 | for k in range(n): 26 | if x.index([i, j, k]).level() > 0.5: 27 | ss = ss + " " + str(k + 1) 28 | break 29 | 30 | print(ss + ' |') 31 | if (i + 1) % m == 0: 32 | print("\n") 33 | 34 | def main(): 35 | 36 | m = 3 37 | n = m * m 38 | 39 | hr_fixed = [[1, 5, 4], 40 | [2, 2, 5], [2, 3, 8], [2, 6, 3], 41 | [3, 2, 1], [3, 4, 2], [3, 5, 8], [3, 7, 9], 42 | [4, 2, 7], [4, 3, 3], [4, 4, 1], [4, 7, 8], [4, 8, 4], 43 | [6, 2, 4], [6, 3, 1], [6, 6, 9], [6, 7, 2], [6, 8, 7], 44 | [7, 3, 4], [7, 5, 6], [7, 6, 5], [7, 8, 8], 45 | [8, 4, 4], [8, 7, 1], [8, 8, 6], 46 | [9, 5, 9] 47 | ] 48 | 49 | fixed = [[f[0] - 1, f[1] - 1, f[2] - 1] for f in hr_fixed] 50 | 51 | with Model('SUDOKU') as M: 52 | x = M.variable("x",[n, n, n], Domain.binary()) 53 | 54 | #each value only once per dimension 55 | for d in range(m): 56 | M.constraint("row_sum(%d)" % d, Expr.sum(x, d), Domain.equalsTo(1.)) 57 | 58 | #each number must appear only once in a block 59 | 60 | for k in range(n): 61 | for i in range(m): 62 | for j in range(m): 63 | M.constraint("blocksum(%d,%d,k=%d)" % (i,j,k), 64 | Expr.sum(x.slice([i * m, j * m, k], [(i + 1) * m, (j + 1) * m, k + 1])), 65 | Domain.equalsTo(1.)) 66 | 67 | M.constraint("fix",x.pick(fixed), Domain.equalsTo(1.0)) 68 | 69 | M.setLogHandler(sys.stdout) 70 | 71 | M.solve() 72 | 73 | M.writeTask("sudoku.task") 74 | 75 | #print the solution, if any... 76 | if M.getPrimalSolutionStatus() in [SolutionStatus.Optimal]: 77 | print_solution(m, x) 78 | else: 79 | print("No solution found!") 80 | 81 | if __name__ == '__main__': 82 | main() -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/python/response.py: -------------------------------------------------------------------------------- 1 | ## 2 | # Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | # 4 | # File : response.py 5 | # 6 | # Purpose : This example demonstrates proper response handling 7 | # for problems solved with the interior-point optimizers. 8 | # 9 | ## 10 | import mosek 11 | import sys 12 | 13 | # A log message 14 | def streamprinter(text): 15 | sys.stdout.write(text) 16 | sys.stdout.flush() 17 | 18 | def main(args): 19 | filename = args[0] if len(args) >= 1 else "../data/cqo1.mps" 20 | 21 | try: 22 | # Create environment and task 23 | with mosek.Env() as env: 24 | with env.Task(0, 0) as task: 25 | # (Optional) set a log stream 26 | # task.set_Stream(mosek.streamtype.log, streamprinter) 27 | 28 | # (Optional) uncomment to see what happens when solution status is unknown 29 | # task.putintparam(mosek.iparam.intpnt_max_iterations, 1) 30 | 31 | # In this example we read data from a file 32 | task.readdata(filename) 33 | 34 | # Optimize 35 | trmcode = task.optimize() 36 | task.solutionsummary(mosek.streamtype.log) 37 | 38 | # We expect solution status OPTIMAL 39 | solsta = task.getsolsta(mosek.soltype.itr) 40 | 41 | if solsta == mosek.solsta.optimal: 42 | # Optimal solution. Fetch and print it. 43 | print("An optimal interior-point solution is located.") 44 | numvar = task.getnumvar() 45 | xx = [ 0.0 ] * numvar 46 | task.getxx(mosek.soltype.itr, xx) 47 | for i in range(numvar): 48 | print("x[{0}] = {1}".format(i, xx[i])) 49 | 50 | elif solsta == mosek.solsta.dual_infeas_cer: 51 | print("Dual infeasibility certificate found.") 52 | 53 | elif solsta == mosek.solsta.prim_infeas_cer: 54 | print("Primal infeasibility certificate found.") 55 | 56 | elif solsta == mosek.solsta.unknown: 57 | # The solutions status is unknown. The termination code 58 | # indicates why the optimizer terminated prematurely. 59 | print("The solution status is unknown.") 60 | symname, desc = mosek.Env.getcodedesc(trmcode) 61 | print(" Termination code: {0} {1}".format(symname, desc)) 62 | 63 | else: 64 | print("An unexpected solution status {0} is obtained.".format(str(solsta))) 65 | 66 | except mosek.Error as e: 67 | print("Unexpected error ({0}) {1}".format(e.errno, e.msg)) 68 | 69 | if __name__ == '__main__': 70 | main(sys.argv[1:]) -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/linux64x86/src/fusion_cxx/IntMap.cc: -------------------------------------------------------------------------------- 1 | #include "fusion_p.h" 2 | #include 3 | #include "monty.h" 4 | 5 | namespace mosek 6 | { 7 | namespace fusion 8 | { 9 | namespace Utils 10 | { 11 | IntMap::IntMap() : _impl(new p_IntMap(this)) {} 12 | bool IntMap::hasItem (long long key) { return _impl->hasItem(key); } 13 | int IntMap::getItem (long long key) { return _impl->getItem(key); } 14 | void IntMap::setItem (long long key, int val) { _impl->setItem(key,val); } 15 | std::shared_ptr> IntMap::keys() { return _impl->keys(); } 16 | std::shared_ptr> IntMap::values() { return _impl->values(); } 17 | 18 | IntMap::t IntMap::clone() { return _impl->clone(); } 19 | IntMap::t IntMap::__mosek_2fusion_2Utils_2IntMap__clone() { return _impl->clone(); } 20 | IntMap::t p_IntMap::__mosek_2fusion_2Utils_2IntMap__clone() { return clone(); } 21 | IntMap::t p_IntMap::clone() 22 | { 23 | IntMap::t pubres = _new_IntMap(); 24 | p_IntMap * res = p_IntMap::_get_impl(pubres.get()); 25 | for (auto iter = m.begin(); iter != m.end(); ++iter) 26 | res->m[iter->first] = iter->second; 27 | 28 | return pubres; 29 | } 30 | 31 | 32 | 33 | 34 | 35 | StringIntMap::StringIntMap() : _impl(new p_StringIntMap(this)) {} 36 | bool StringIntMap::hasItem (const std::string & key) { return _impl->hasItem(key); } 37 | int StringIntMap::getItem (const std::string & key) { return _impl->getItem(key); } 38 | void StringIntMap::setItem (const std::string & key, int val) { _impl->setItem(key,val); } 39 | std::shared_ptr> StringIntMap::keys() { return _impl->keys(); } 40 | std::shared_ptr> StringIntMap::values() { return _impl->values(); } 41 | 42 | StringIntMap::t StringIntMap::clone() { return _impl->clone(); } 43 | StringIntMap::t StringIntMap::__mosek_2fusion_2Utils_2StringIntMap__clone() { return _impl->clone(); } 44 | StringIntMap::t p_StringIntMap::__mosek_2fusion_2Utils_2StringIntMap__clone() { return clone(); } 45 | StringIntMap::t p_StringIntMap::clone() { 46 | StringIntMap::t pubres = _new_StringIntMap(); 47 | p_StringIntMap * res = p_StringIntMap::_get_impl(pubres.get()); 48 | for (auto iter = m.begin(); iter != m.end(); ++iter) 49 | res->m[iter->first] = iter->second; 50 | 51 | return pubres; 52 | } 53 | 54 | 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/platform/osx64x86/src/fusion_cxx/IntMap.cc: -------------------------------------------------------------------------------- 1 | #include "fusion_p.h" 2 | #include 3 | #include "monty.h" 4 | 5 | namespace mosek 6 | { 7 | namespace fusion 8 | { 9 | namespace Utils 10 | { 11 | IntMap::IntMap() : _impl(new p_IntMap(this)) {} 12 | bool IntMap::hasItem (long long key) { return _impl->hasItem(key); } 13 | int IntMap::getItem (long long key) { return _impl->getItem(key); } 14 | void IntMap::setItem (long long key, int val) { _impl->setItem(key,val); } 15 | std::shared_ptr> IntMap::keys() { return _impl->keys(); } 16 | std::shared_ptr> IntMap::values() { return _impl->values(); } 17 | 18 | IntMap::t IntMap::clone() { return _impl->clone(); } 19 | IntMap::t IntMap::__mosek_2fusion_2Utils_2IntMap__clone() { return _impl->clone(); } 20 | IntMap::t p_IntMap::__mosek_2fusion_2Utils_2IntMap__clone() { return clone(); } 21 | IntMap::t p_IntMap::clone() 22 | { 23 | IntMap::t pubres = _new_IntMap(); 24 | p_IntMap * res = p_IntMap::_get_impl(pubres.get()); 25 | for (auto iter = m.begin(); iter != m.end(); ++iter) 26 | res->m[iter->first] = iter->second; 27 | 28 | return pubres; 29 | } 30 | 31 | 32 | 33 | 34 | 35 | StringIntMap::StringIntMap() : _impl(new p_StringIntMap(this)) {} 36 | bool StringIntMap::hasItem (const std::string & key) { return _impl->hasItem(key); } 37 | int StringIntMap::getItem (const std::string & key) { return _impl->getItem(key); } 38 | void StringIntMap::setItem (const std::string & key, int val) { _impl->setItem(key,val); } 39 | std::shared_ptr> StringIntMap::keys() { return _impl->keys(); } 40 | std::shared_ptr> StringIntMap::values() { return _impl->values(); } 41 | 42 | StringIntMap::t StringIntMap::clone() { return _impl->clone(); } 43 | StringIntMap::t StringIntMap::__mosek_2fusion_2Utils_2StringIntMap__clone() { return _impl->clone(); } 44 | StringIntMap::t p_StringIntMap::__mosek_2fusion_2Utils_2StringIntMap__clone() { return clone(); } 45 | StringIntMap::t p_StringIntMap::clone() { 46 | StringIntMap::t pubres = _new_StringIntMap(); 47 | p_StringIntMap * res = p_StringIntMap::_get_impl(pubres.get()); 48 | for (auto iter = m.begin(); iter != m.end(); ++iter) 49 | res->m[iter->first] = iter->second; 50 | 51 | return pubres; 52 | } 53 | 54 | 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /third_party/mosek/9.0/tools/examples/fusion/cxx/facility_location.cc: -------------------------------------------------------------------------------- 1 | //// 2 | // Copyright: Copyright (c) MOSEK ApS, Denmark. All rights reserved. 3 | // 4 | // File: facility_location.cc 5 | // 6 | // Purpose: Demonstrates a small one-facility location problem. 7 | // 8 | // Given 10 customers placed in a grid we wish to place a facility 9 | // somewhere so that the total sum of distances to customers is 10 | // minimized. 11 | // 12 | // The problem is formulated as a conic optimization problem as follows. 13 | // Let f=(fx,fy) be the (unknown) location of the facility, and let 14 | // c_i=(cx_i,cy_i) be the (known) customer locations; then we wish to 15 | // minimize 16 | // sum_i || f - c_i || 17 | // where 18 | // ||.|| 19 | // denotes the euclidian norm. 20 | // This is formulated as 21 | // 22 | // minimize sum(d_i) 23 | // such that d_i ^ 2 > tx_i ^ 2 + ty_i ^ 2, for all i 24 | // tx_i = cx_i - fx, for all i 25 | // ty_i = cy_i - fy, for all i 26 | // d_i > 0, for all i 27 | //// 28 | 29 | #include 30 | #include 31 | #include 32 | #include "fusion.h" 33 | 34 | using namespace mosek::fusion; 35 | using namespace monty; 36 | 37 | int main(int argc, char ** argv) 38 | { 39 | auto customerloc = new_array_ptr( 40 | { {12., 2. }, 41 | {15., 13. }, 42 | {10., 8. }, 43 | { 0., 10. }, 44 | { 6., 13. }, 45 | { 5., 8. }, 46 | {10., 12. }, 47 | { 4., 6. }, 48 | { 5., 2. }, 49 | { 1., 10. } 50 | } ); 51 | int N = customerloc->size(0); 52 | Model::t M = new Model("FacilityLocation"); auto _M = finally([&]() { M->dispose(); }); 53 | // Variable holding the facility location 54 | Variable::t f = M->variable("facility", Set::make(1, 2), Domain::unbounded()); 55 | // Variable defining the euclidian distances to each customer 56 | Variable::t d = M->variable("dist", Set::make(N, 1), Domain::greaterThan(0.0)); 57 | // Variable defining the x and y differences to each customer; 58 | Variable::t t = M->variable("t", Set::make(N, 2), Domain::unbounded()); 59 | M->constraint("dist measure", 60 | Var::hstack(d, t), 61 | Domain::inQCone(N, 3)); 62 | 63 | Variable::t fxy = Var::repeat(f, N); 64 | M->constraint("xy diff", Expr::add(t, fxy), Domain::equalsTo(customerloc)); 65 | 66 | 67 | M->objective("total_dist", ObjectiveSense::Minimize, Expr::sum(d)); 68 | 69 | M->solve(); 70 | 71 | auto res = f->level(); 72 | std::cout << std::setprecision(2) 73 | << "Facility location = " << (*res)[0] << "," << (*res)[1] << std::endl; 74 | } --------------------------------------------------------------------------------