├── .ci
├── .travis.pre
└── appveyor.pre
├── .coin-or
└── projDesc.xml
├── .gitattributes
├── .gitignore
├── .travis.yml
├── AUTHORS
├── Dependencies
├── FlopCpp
├── AUTHORS
├── LICENSE
├── MSVisualStudio
│ └── v9
│ │ ├── FlopCpp.sln
│ │ ├── FlopCpp
│ │ ├── FlopCpp.vcproj
│ │ └── unitTest
│ │ │ └── unitTest.vcproj
│ │ ├── examples
│ │ ├── aircraft
│ │ │ └── aircraft.vcproj
│ │ ├── ampl
│ │ │ └── ampl.vcproj
│ │ ├── bid
│ │ │ └── bid.vcproj
│ │ ├── coex
│ │ │ └── coex.vcproj
│ │ ├── coexx
│ │ │ └── coexx.vcproj
│ │ ├── cross
│ │ │ └── cross.vcproj
│ │ ├── cuttingStock
│ │ │ └── cuttingStock.vcproj
│ │ ├── gapmin
│ │ │ └── gapmin.vcproj
│ │ ├── magic
│ │ │ └── magic.vcproj
│ │ ├── mine
│ │ │ └── mine.vcproj
│ │ ├── multiProduct
│ │ │ └── multiProduct.vcproj
│ │ ├── sodoku
│ │ │ └── sodoku.vcproj
│ │ ├── stochBenders
│ │ │ └── stochBenders.vcproj
│ │ ├── sudoku
│ │ │ └── sudoku.vcproj
│ │ ├── tap
│ │ │ └── tap.vcproj
│ │ ├── train
│ │ │ └── train.vcproj
│ │ ├── transport
│ │ │ └── transport.vcproj
│ │ └── xbsl
│ │ │ └── xbsl.vcproj
│ │ └── libflopc.vcproj
├── Makefile.am
├── Makefile.in
├── README
├── config.guess
├── config.sub
├── configure
├── configure.ac
├── depcomp
├── doxydoc
│ └── doxygen.conf.in
├── examples
│ ├── CEPFlopCppModel.cpp
│ ├── Makefile.in
│ ├── aircraft.cpp
│ ├── ampl.cpp
│ ├── bid.cpp
│ ├── coex.cpp
│ ├── coexx.cpp
│ ├── cross.cpp
│ ├── cuttingStock.cpp
│ ├── fixed.dat
│ ├── gapmin.cpp
│ ├── magic.cpp
│ ├── mine.cpp
│ ├── multiProduct.cpp
│ ├── runall
│ ├── runone
│ ├── stampl.cpp
│ ├── stampl2.cpp
│ ├── stochbenders.cpp
│ ├── sudoku.cpp
│ ├── tap.cpp
│ ├── train.cpp
│ ├── train.dat
│ ├── transport.cpp
│ └── xbsl.cpp
├── flopcpp-uninstalled.pc.in
├── flopcpp.pc.in
├── install-sh
├── ltmain.sh
├── missing
├── src
│ ├── FlopCppConfig.h
│ ├── MP_boolean.cpp
│ ├── MP_boolean.hpp
│ ├── MP_constant.cpp
│ ├── MP_constant.hpp
│ ├── MP_constraint.cpp
│ ├── MP_constraint.hpp
│ ├── MP_data.cpp
│ ├── MP_data.hpp
│ ├── MP_domain.cpp
│ ├── MP_domain.hpp
│ ├── MP_expression.cpp
│ ├── MP_expression.hpp
│ ├── MP_index.cpp
│ ├── MP_index.hpp
│ ├── MP_model.cpp
│ ├── MP_model.hpp
│ ├── MP_set.cpp
│ ├── MP_set.hpp
│ ├── MP_utilities.cpp
│ ├── MP_utilities.hpp
│ ├── MP_variable.cpp
│ ├── MP_variable.hpp
│ ├── Makefile.am
│ ├── Makefile.in
│ ├── config.h.in
│ ├── config_flopcpp.h.in
│ ├── config_flopcpp_default.h
│ ├── flopc.cpp
│ └── flopc.hpp
├── test
│ ├── Makefile.am
│ ├── Makefile.in
│ └── unitTest.cpp
└── unittest
│ ├── Makefile.am
│ ├── Makefile.in
│ ├── TestBed.cpp
│ ├── TestBed.hpp
│ ├── TestItem.cpp
│ ├── TestItem.hpp
│ ├── booleanTest.cpp
│ ├── constantTest.cpp
│ ├── indexTest.cpp
│ ├── setTest.cpp
│ ├── unitTest.cpp
│ └── unitTest.hpp
├── INSTALL
├── LICENSE
├── Makefile.am
├── Makefile.in
├── README
├── appveyor.yml
├── config.guess
├── config.sub
├── configure
├── configure.ac
├── depcomp
├── doxydoc
└── doxygen.conf
├── install-sh
├── ltmain.sh
└── missing
/.ci/.travis.pre:
--------------------------------------------------------------------------------
1 | language: cpp
2 |
3 |
--------------------------------------------------------------------------------
/.ci/appveyor.pre:
--------------------------------------------------------------------------------
1 | platform:
2 | - x64
3 |
4 | environment:
5 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto !eol
2 | .coin-or/projDesc.xml -text
3 | /.travis.yml -text
4 | /AUTHORS -text
5 | /Dependencies -text
6 | FlopCpp/AUTHORS -text
7 | FlopCpp/LICENSE -text
8 | FlopCpp/MSVisualStudio/v9/FlopCpp.sln -text
9 | FlopCpp/MSVisualStudio/v9/FlopCpp/FlopCpp.vcproj -text
10 | FlopCpp/MSVisualStudio/v9/FlopCpp/unitTest/unitTest.vcproj -text
11 | FlopCpp/MSVisualStudio/v9/examples/aircraft/aircraft.vcproj -text
12 | FlopCpp/MSVisualStudio/v9/examples/ampl/ampl.vcproj -text
13 | FlopCpp/MSVisualStudio/v9/examples/bid/bid.vcproj -text
14 | FlopCpp/MSVisualStudio/v9/examples/coex/coex.vcproj -text
15 | FlopCpp/MSVisualStudio/v9/examples/coexx/coexx.vcproj -text
16 | FlopCpp/MSVisualStudio/v9/examples/cross/cross.vcproj -text
17 | FlopCpp/MSVisualStudio/v9/examples/cuttingStock/cuttingStock.vcproj -text
18 | FlopCpp/MSVisualStudio/v9/examples/gapmin/gapmin.vcproj -text
19 | FlopCpp/MSVisualStudio/v9/examples/magic/magic.vcproj -text
20 | FlopCpp/MSVisualStudio/v9/examples/mine/mine.vcproj -text
21 | FlopCpp/MSVisualStudio/v9/examples/multiProduct/multiProduct.vcproj -text
22 | FlopCpp/MSVisualStudio/v9/examples/sodoku/sodoku.vcproj -text
23 | FlopCpp/MSVisualStudio/v9/examples/stochBenders/stochBenders.vcproj -text
24 | FlopCpp/MSVisualStudio/v9/examples/sudoku/sudoku.vcproj -text
25 | FlopCpp/MSVisualStudio/v9/examples/tap/tap.vcproj -text
26 | FlopCpp/MSVisualStudio/v9/examples/train/train.vcproj -text
27 | FlopCpp/MSVisualStudio/v9/examples/transport/transport.vcproj -text
28 | FlopCpp/MSVisualStudio/v9/examples/xbsl/xbsl.vcproj -text
29 | FlopCpp/MSVisualStudio/v9/libflopc.vcproj -text
30 | FlopCpp/README -text
31 | FlopCpp/config.guess -text
32 | FlopCpp/config.sub -text
33 | FlopCpp/configure -text
34 | FlopCpp/depcomp -text
35 | FlopCpp/doxydoc/doxygen.conf.in -text
36 | FlopCpp/examples/CEPFlopCppModel.cpp -text
37 | FlopCpp/examples/aircraft.cpp -text
38 | FlopCpp/examples/ampl.cpp -text
39 | FlopCpp/examples/bid.cpp -text
40 | FlopCpp/examples/coex.cpp -text
41 | FlopCpp/examples/coexx.cpp -text
42 | FlopCpp/examples/cross.cpp -text
43 | FlopCpp/examples/cuttingStock.cpp -text
44 | FlopCpp/examples/fixed.dat -text
45 | FlopCpp/examples/gapmin.cpp -text
46 | FlopCpp/examples/magic.cpp -text
47 | FlopCpp/examples/mine.cpp -text
48 | FlopCpp/examples/multiProduct.cpp -text
49 | FlopCpp/examples/runall -text
50 | FlopCpp/examples/runone -text
51 | FlopCpp/examples/stampl.cpp -text
52 | FlopCpp/examples/stampl2.cpp -text
53 | FlopCpp/examples/stochbenders.cpp -text
54 | FlopCpp/examples/sudoku.cpp -text
55 | FlopCpp/examples/tap.cpp -text
56 | FlopCpp/examples/train.cpp -text
57 | FlopCpp/examples/train.dat -text
58 | FlopCpp/examples/transport.cpp -text
59 | FlopCpp/examples/xbsl.cpp -text
60 | FlopCpp/flopcpp-uninstalled.pc.in -text
61 | FlopCpp/flopcpp.pc.in -text
62 | FlopCpp/install-sh -text
63 | FlopCpp/ltmain.sh -text
64 | FlopCpp/missing -text
65 | FlopCpp/src/FlopCppConfig.h -text
66 | FlopCpp/src/MP_boolean.cpp -text
67 | FlopCpp/src/MP_boolean.hpp -text
68 | FlopCpp/src/MP_constant.cpp -text
69 | FlopCpp/src/MP_constant.hpp -text
70 | FlopCpp/src/MP_constraint.cpp -text
71 | FlopCpp/src/MP_constraint.hpp -text
72 | FlopCpp/src/MP_data.cpp -text
73 | FlopCpp/src/MP_data.hpp -text
74 | FlopCpp/src/MP_domain.cpp -text
75 | FlopCpp/src/MP_domain.hpp -text
76 | FlopCpp/src/MP_expression.cpp -text
77 | FlopCpp/src/MP_expression.hpp -text
78 | FlopCpp/src/MP_index.cpp -text
79 | FlopCpp/src/MP_index.hpp -text
80 | FlopCpp/src/MP_model.cpp -text
81 | FlopCpp/src/MP_model.hpp -text
82 | FlopCpp/src/MP_set.cpp -text
83 | FlopCpp/src/MP_set.hpp -text
84 | FlopCpp/src/MP_utilities.cpp -text
85 | FlopCpp/src/MP_utilities.hpp -text
86 | FlopCpp/src/MP_variable.cpp -text
87 | FlopCpp/src/MP_variable.hpp -text
88 | FlopCpp/src/config.h.in -text
89 | FlopCpp/src/config_flopcpp.h.in -text
90 | FlopCpp/src/config_flopcpp_default.h -text
91 | FlopCpp/src/flopc.cpp -text
92 | FlopCpp/src/flopc.hpp -text
93 | FlopCpp/test/unitTest.cpp -text
94 | FlopCpp/unittest/Makefile.am -text
95 | FlopCpp/unittest/Makefile.in -text
96 | FlopCpp/unittest/TestBed.cpp -text
97 | FlopCpp/unittest/TestBed.hpp -text
98 | FlopCpp/unittest/TestItem.cpp -text
99 | FlopCpp/unittest/TestItem.hpp -text
100 | FlopCpp/unittest/booleanTest.cpp -text
101 | FlopCpp/unittest/constantTest.cpp -text
102 | FlopCpp/unittest/indexTest.cpp -text
103 | FlopCpp/unittest/setTest.cpp -text
104 | FlopCpp/unittest/unitTest.cpp -text
105 | FlopCpp/unittest/unitTest.hpp -text
106 | /INSTALL -text
107 | /LICENSE -text
108 | /README -text
109 | /appveyor.yml -text
110 | /config.guess -text
111 | /config.sub -text
112 | /configure -text
113 | /depcomp -text
114 | doxydoc/doxygen.conf -text
115 | /install-sh -text
116 | /ltmain.sh -text
117 | /missing -text
118 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 |
3 | matrix:
4 | include:
5 | - os: linux
6 | addons:
7 | apt:
8 | packages:
9 | - gfortran
10 | - liblapack-dev
11 | - os: linux
12 | dist: bionic
13 | addons:
14 | apt:
15 | packages:
16 | - gfortran
17 | - liblapack-dev
18 | - os: osx
19 | osx_image: xcode11
20 | env: OSX=10.14 CC=gcc CXX=g++
21 | compiler: clang
22 | - os: osx
23 | osx_image: xcode11
24 | env: OSX=10.14
25 | compiler: clang
26 | - os: osx
27 | osx_image: xcode10
28 | env: OSX=10.13
29 | compiler: clang
30 | - os: osx
31 | osx_image: xcode9.2
32 | env: OSX=10.12
33 | compiler: clang
34 |
35 | before_script:
36 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install bash gcc; clang --version; gfortran --version; fi
37 | - if [[ "$TRAVIS_OS_NAME $CC" == "osx gcc" ]]; then export CC=gcc-9 ; export CXX=g++-9 ; $CC --version; $CXX --version; fi
38 | - cd ..
39 | - wget https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
40 | - export PROJECT_URL=https://github.com/$TRAVIS_REPO_SLUG
41 | - export PROJECT=`echo $TRAVIS_REPO_SLUG | cut -d "/" -f 2`
42 | - bash ./coinbrew fetch $PROJECT_URL:$TRAVIS_BRANCH --no-prompt --skip-update > /dev/null
43 |
44 | script:
45 | - bash ./coinbrew build $PROJECT --no-prompt --verbosity=2 --test
46 |
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | For FlopCpp author information, please see the AUTHORS file in the FlopCpp
2 | subdirectory. For author information for any other COIN-OR or third-party
3 | source code that was automatically checked out with FlopCpp, please see the
4 | FlopCpp file in the appropriate subdirectories.
--------------------------------------------------------------------------------
/Dependencies:
--------------------------------------------------------------------------------
1 | BuildTools https://projects.coin-or.org/svn/BuildTools/stable/0.8
2 | CoinUtils https://projects.coin-or.org/svn/CoinUtils/stable/2.11/CoinUtils
3 | Osi https://projects.coin-or.org/svn/Osi/stable/0.108/Osi
4 | Clp https://projects.coin-or.org/svn/Clp/stable/1.17/Clp
5 | Cgl https://projects.coin-or.org/svn/Cgl/stable/0.60/Cgl
6 | Cbc https://projects.coin-or.org/svn/Cbc/stable/2.10/Cbc
7 |
--------------------------------------------------------------------------------
/FlopCpp/AUTHORS:
--------------------------------------------------------------------------------
1 | Hultberg, Tim H.
2 | Walton, H. Philip
3 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/aircraft/aircraft.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
73 |
76 |
79 |
82 |
85 |
88 |
91 |
94 |
95 |
103 |
106 |
109 |
112 |
115 |
118 |
128 |
131 |
134 |
137 |
148 |
151 |
154 |
157 |
160 |
163 |
166 |
169 |
170 |
171 |
172 |
173 |
174 |
179 |
182 |
183 |
184 |
189 |
190 |
195 |
196 |
197 |
198 |
199 |
200 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/ampl/ampl.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/bid/bid.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/coex/coex.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/coexx/coexx.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/cross/cross.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/cuttingStock/cuttingStock.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/gapmin/gapmin.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/magic/magic.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/mine/mine.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/multiProduct/multiProduct.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/sodoku/sodoku.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/sudoku/sudoku.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/MSVisualStudio/v9/examples/tap/tap.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
26 |
29 |
32 |
35 |
38 |
41 |
54 |
57 |
60 |
63 |
72 |
75 |
78 |
81 |
84 |
87 |
90 |
93 |
94 |
102 |
105 |
108 |
111 |
114 |
117 |
127 |
130 |
133 |
136 |
147 |
150 |
153 |
156 |
159 |
162 |
165 |
168 |
169 |
170 |
171 |
172 |
173 |
178 |
181 |
182 |
183 |
188 |
189 |
194 |
195 |
196 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/FlopCpp/Makefile.am:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2006 International Business Machines and others.
2 | # All Rights Reserved.
3 | # This file is distributed under the Common Public License.
4 |
5 | ## $Id$
6 |
7 | # Author: Andreas Waechter IBM 2006-04-13
8 |
9 | AUTOMAKE_OPTIONS = foreign
10 |
11 | ########################################################################
12 | # Subdirectories #
13 | ########################################################################
14 |
15 | SUBDIRS = src
16 |
17 | # We don't want to compile the test subdirectory, unless the test target is
18 | # specified. But we need to list it as subdirectory to make sure that it is
19 | # included in the tarball
20 |
21 | if ALWAYS_FALSE
22 | SUBDIRS += test
23 | endif
24 |
25 | ########################################################################
26 | # Additional files to be included in tarball #
27 | ########################################################################
28 |
29 | # Here we need include all files that are not mentioned in other Makefiles
30 |
31 | EXTRA_DIST =
32 |
33 | ########################################################################
34 | # Extra Targets #
35 | ########################################################################
36 |
37 | test: all
38 | cd unittest; make test
39 | cd test; make test
40 |
41 | unitTest: test
42 |
43 | # Doxygen documentation
44 |
45 | doxydoc:
46 | doxygen doxydoc/doxygen.conf
47 |
48 | clean-doxydoc:
49 | ( cd doxydoc ; rm -rf html *.log *.tag )
50 |
51 | clean-local: clean-doxydoc
52 | if test -r test/Makefile; then cd test; make clean; fi
53 | if test -r unittest/Makefile; then cd unittest; make clean; fi
54 |
55 | distclean-local:
56 | if test -r test/Makefile; then cd test; make distclean; fi
57 | if test -r unittest/Makefile; then cd unittest; make distclean; fi
58 |
59 | install-exec-local: install-doc
60 |
61 | uninstall-local: uninstall-doc
62 |
63 | .PHONY: test unitTest doxydoc
64 |
65 | ########################################################################
66 | # Installation of the addlibs file #
67 | ########################################################################
68 |
69 | pkgconfiglibdir = $(libdir)/pkgconfig
70 | pkgconfiglib_DATA = flopcpp.pc
71 |
72 | addlibsdir = $(DESTDIR)$(datadir)/coin/doc/FlopCpp
73 |
74 | install-data-hook:
75 | @$(mkdir_p) "$(addlibsdir)"
76 | if COIN_HAS_PKGCONFIG
77 | PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@:$(DESTDIR)$(pkgconfiglibdir) \
78 | $(PKG_CONFIG) --libs flopcpp > $(addlibsdir)/flopcpp_addlibs.txt
79 | else
80 | if COIN_CXX_IS_CL
81 | echo "-libpath:`$(CYGPATH_W) @abs_lib_dir@` libFlopCpp.lib @FLOPCPP_LIBS_INSTALLED@" > $(addlibsdir)/flopcpp_addlibs.txt
82 | else
83 | echo -L@abs_lib_dir@ -lFlopCpp @FLOPCPP_LIBS_INSTALLED@ > $(addlibsdir)/flopcpp_addlibs.txt
84 | endif
85 | endif
86 |
87 | uninstall-hook:
88 | rm -f $(addlibsdir)/flopcpp_addlibs.txt
89 |
90 | ########################################################################
91 | # Maintainer Stuff #
92 | ########################################################################
93 |
94 | # Files that are generated and should be cleaned with make distclean
95 | DISTCLEANFILES =
96 |
97 | include BuildTools/Makemain.inc
98 |
--------------------------------------------------------------------------------
/FlopCpp/README:
--------------------------------------------------------------------------------
1 | FlopCpp Readme
2 | ==============
3 |
4 | For information on using FlopCpp please see:
5 | https://projects.coin-or.org/FlopC++
--------------------------------------------------------------------------------
/FlopCpp/configure.ac:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2006 International Business Machines.
2 | # All Rights Reserved.
3 | # This file is distributed under the Eclipse Public License.
4 |
5 | ## $Id: configure.ac 369 2006-06-14 01:19:26Z andreasw $
6 |
7 | # Author: Andreas Waechter IBM 2006-04-13
8 |
9 | #############################################################################
10 | # Names and other basic things #
11 | #############################################################################
12 |
13 | AC_PREREQ(2.59)
14 |
15 | AC_INIT([FlopCpp],[trunk],[flopcpp@list.coin-or.org])
16 |
17 | AC_COPYRIGHT([
18 | Copyright 2006 International Business Machines and others.
19 | All Rights Reserved.
20 | This file is part of the open source package FlopC++ which is distributed
21 | under the Common Public License.])
22 |
23 | # List one file in the package so that the configure script can test
24 | # whether the package is actually there
25 | AC_CONFIG_SRCDIR(src/flopc.hpp)
26 |
27 | # Where should everything be installed by default? Here, we want it
28 | # to be installed directly in 'bin', 'lib', 'include' subdirectories
29 | # of the directory where configure is run. The default would be
30 | # /usr/local.
31 | AC_PREFIX_DEFAULT([`pwd`])
32 |
33 | #############################################################################
34 | # Standard build tool stuff #
35 | #############################################################################
36 |
37 | # Get the system type
38 | AC_CANONICAL_BUILD
39 |
40 | # If this project depends on external projects, the Externals file in
41 | # the source root directory contains definition of where to find those
42 | # externals. The following macro ensures that those externals are
43 | # retrieved by svn if they are not there yet.
44 | AC_COIN_PROJECTDIR_INIT(FlopCpp)
45 |
46 | # Check if user wants to produce debugging code
47 | AC_COIN_DEBUG_COMPILE(FlopCpp)
48 |
49 | # Get the name of the C++ compiler and appropriate compiler options
50 | AC_COIN_PROG_CXX
51 |
52 | # Initialize automake and libtool
53 | AC_COIN_INIT_AUTO_TOOLS
54 |
55 | #############################################################################
56 | # COIN components #
57 | #############################################################################
58 |
59 | AC_COIN_CHECK_PACKAGE(Osi, [osi], [FlopCpp])
60 | if test $coin_has_osi != yes ; then
61 | AC_MSG_ERROR([Required package Osi not available.])
62 | fi
63 | AC_COIN_CHECK_PACKAGE(Cbc, [osi-cbc])
64 | AC_COIN_CHECK_PACKAGE(Clp, [osi-clp])
65 |
66 | ##############################################################################
67 | # VPATH links for example input files #
68 | ##############################################################################
69 |
70 | # In case this is a VPATH configuration we need to make sure that the
71 | # input files for the examples are available in the VPATH directory.
72 |
73 | AC_COIN_VPATH_LINK(examples/fixed.dat)
74 | AC_COIN_VPATH_LINK(examples/train.dat)
75 | AC_COIN_VPATH_LINK(examples/aircraft.cpp)
76 | AC_COIN_VPATH_LINK(examples/ampl.cpp)
77 | AC_COIN_VPATH_LINK(examples/bid.cpp)
78 | AC_COIN_VPATH_LINK(examples/CEPFlopCppModel.cpp)
79 | AC_COIN_VPATH_LINK(examples/coex.cpp)
80 | AC_COIN_VPATH_LINK(examples/coexx.cpp)
81 | AC_COIN_VPATH_LINK(examples/cross.cpp)
82 | AC_COIN_VPATH_LINK(examples/cuttingStock.cpp)
83 | AC_COIN_VPATH_LINK(examples/gapmin.cpp)
84 | AC_COIN_VPATH_LINK(examples/magic.cpp)
85 | AC_COIN_VPATH_LINK(examples/mine.cpp)
86 | AC_COIN_VPATH_LINK(examples/multiProduct.cpp)
87 | AC_COIN_VPATH_LINK(examples/stampl2.cpp)
88 | AC_COIN_VPATH_LINK(examples/stampl.cpp)
89 | AC_COIN_VPATH_LINK(examples/stochbenders.cpp)
90 | AC_COIN_VPATH_LINK(examples/sudoku.cpp)
91 | AC_COIN_VPATH_LINK(examples/tap.cpp)
92 | AC_COIN_VPATH_LINK(examples/train.cpp)
93 | AC_COIN_VPATH_LINK(examples/transport.cpp)
94 | AC_COIN_VPATH_LINK(examples/xbsl.cpp)
95 | AC_COIN_VPATH_LINK(examples/runall)
96 | AC_COIN_VPATH_LINK(examples/runone)
97 |
98 | #############################################################################
99 | # Check for doxygen #
100 | #############################################################################
101 |
102 | AC_COIN_DOXYGEN(CoinUtils Osi Clp Cgl Cbc)
103 |
104 | ##############################################################################
105 | # Finishing up by writing all the output #
106 | ##############################################################################
107 |
108 | # Here list all the files that configure should create (except for the
109 | # configuration header file)
110 | AC_CONFIG_FILES([Makefile
111 | examples/Makefile
112 | src/Makefile
113 | test/Makefile
114 | unittest/Makefile
115 | flopcpp.pc
116 | flopcpp-uninstalled.pc
117 | doxydoc/doxygen.conf])
118 |
119 | # Here put the location and name of the configuration header file
120 | AC_CONFIG_HEADER([src/config.h src/config_flopcpp.h])
121 |
122 | # Finally, we let configure write all the output...
123 | AC_COIN_FINALIZE
124 |
--------------------------------------------------------------------------------
/FlopCpp/examples/Makefile.in:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2006 International Business Machines and others.
2 | # All Rights Reserved.
3 | # This file is distributed under the Common Public License.
4 |
5 | # $Id: Makefile.in 726 2006-04-17 04:16:00Z andreasw $
6 |
7 | ##########################################################################
8 | # You can modify this example makefile to fit for your own program. #
9 | # Usually, you only need to change the five CHANGEME entries below. #
10 | ##########################################################################
11 |
12 | # To compile other examples, either changed the following line, or
13 | # add the argument EXNAME=example_name to make
14 | EXNAME = aircraft
15 |
16 | # CHANGEME: This should be the name of your executable
17 | EXE = $(EXNAME)@EXEEXT@
18 |
19 | # CHANGEME: Here is the name of all object files corresponding to the source
20 | # code that you wrote in order to define the problem statement
21 | OBJS = $(EXNAME).@OBJEXT@
22 |
23 | # CHANGEME: Additional libraries
24 | ADDLIBS =
25 |
26 | # CHANGEME: Additional flags for compilation (e.g., include flags)
27 | ADDINCFLAGS =
28 |
29 | # CHANGEME: Directory to the sources for the (example) problem definition
30 | # files
31 | SRCDIR = @srcdir@
32 | VPATH = @srcdir@
33 |
34 | ##########################################################################
35 | # Usually, you don't have to change anything below. Note that if you #
36 | # change certain compiler options, you might have to recompile the #
37 | # COIN package. #
38 | ##########################################################################
39 |
40 | COIN_HAS_PKGCONFIG = @COIN_HAS_PKGCONFIG_TRUE@TRUE
41 | COIN_CXX_IS_CL = @COIN_CXX_IS_CL_TRUE@TRUE
42 | COIN_HAS_DATASTOCHASTIC = @COIN_HAS_DATASTOCHASTIC_TRUE@TRUE
43 |
44 | # C++ Compiler command
45 | CXX = @CXX@
46 |
47 | # C++ Compiler options
48 | CXXFLAGS = @CXXFLAGS@
49 |
50 | # additional C++ Compiler options for linking
51 | CXXLINKFLAGS = @RPATH_FLAGS@
52 |
53 | # Include directories (we use the CYGPATH_W variables to allow compilation with Windows compilers)
54 | ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
55 | INCL = `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --cflags flopcpp osi-cbc osi-clp`
56 | else
57 | INCL = @FLOPCPP_CFLAGS_INSTALLED@ @CBC_CFLAGS_INSTALLED@ @CLP_CFLAGS_INSTALLED@
58 | endif
59 | INCL += $(ADDINCFLAGS)
60 |
61 | # Linker flags
62 | ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
63 | LIBS = `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --libs flopcpp osi-cbc osi-clp`
64 | else
65 | ifeq ($(COIN_CXX_IS_CL), TRUE)
66 | LIBS = -link -libpath:`$(CYGPATH_W) @abs_lib_dir@` libSmi.lib @FLOPCPP_LIBS_INSTALLED@ @CBC_LIBS_INSTALLED@ @CLP_LIBS_INSTALLED@
67 | else
68 | LIBS = -L@abs_lib_dir@ -lFlopCpp @CBC_LIBS_INSTALLED@ @CLP_LIBS_INSTALLED@
69 | endif
70 | endif
71 |
72 | # The following is necessary under cygwin, if native compilers are used
73 | CYGPATH_W = @CYGPATH_W@
74 |
75 | all: $(EXE)
76 |
77 | .SUFFIXES: .cpp .o .obj
78 |
79 | $(EXE): $(OBJS)
80 | bla=;\
81 | for file in $(OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; done; \
82 | $(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(LIBS) $(ADDLIBS)
83 |
84 | clean:
85 | rm -rf $(EXE) $(OBJS)
86 |
87 | .cpp.o:
88 | $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
89 |
90 | .cpp.obj:
91 | $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
92 |
--------------------------------------------------------------------------------
/FlopCpp/examples/ampl.cpp:
--------------------------------------------------------------------------------
1 | // $Id$
2 | #include "flopc.hpp"
3 | using namespace flopc;
4 | using namespace std;
5 | #include
6 | #include
7 |
8 | /* A sample problem to demonstrate the power of modeling systems
9 | Fourer, R, Gay, D M, and Kernighan, B W, AMPL: A Mathematical Programming
10 | Language. AT\&T Bell Laboratories, Murray Hill, New Jersey, 1987.
11 | */
12 |
13 | int main() {
14 | MP_model &model = MP_model::getDefaultModel();
15 | model.setSolver(new OsiCbcSolverInterface(new OsiClpSolverInterface));
16 | model.verbose();
17 |
18 | enum {iron, nickel, numRaw};
19 | enum {nuts, bolts, washers, numPrd};
20 | const int numT = 4;
21 |
22 | MP_set
23 | prd(numPrd), // products / nuts, bolts, washers /
24 | raw(numRaw), // raw materials / iron, nickel /
25 | TL(numT+1); // extended t / 1 * 5 /
26 |
27 | MP_subset<1>
28 | T(TL), // periods / 1 * 4 /
29 | first(TL), // / 1 /
30 | last(TL); // / 5 /
31 |
32 | T.insert(0);
33 | T.insert(1);
34 | T.insert(2);
35 | T.insert(3);
36 |
37 | first.insert(0);
38 | last.insert(4);
39 |
40 | MP_data istock(raw); // initial stock / iron 35.8 , nickel 7.32 /
41 | MP_data scost(raw); // storage cost / iron .03, nickel .025 /
42 | MP_data rvalue(raw); // residual value / iron .02, nickel -.01 /
43 |
44 | istock(iron) = 35.8; istock(nickel) = 7.32;
45 | scost(iron) = 0.03; scost(nickel) = 0.025;
46 | rvalue(iron) = 0.02; rvalue(nickel) =-0.01;
47 |
48 | double m = 123; // maximum production
49 |
50 | MP_data units(raw,prd); // raw material inputs to produce a unit of product
51 |
52 | double avalue[numRaw][numPrd] = {{ .79, .83, .92 },
53 | { .21, .17, .08 }};
54 |
55 | units.value(&avalue[0][0]);
56 |
57 | MP_data profit(prd,T); // profit
58 |
59 | double cvalue[numPrd][numT] = {{ 1.73, 1.8, 1.6, 2.2 },
60 | { 1.82, 1.9, 1.7, .95},
61 | { 1.05, 1.1, .95, 1.33}};
62 |
63 | profit.value(&cvalue[0][0]);
64 |
65 | MP_variable x(prd,TL); // production level
66 | x.setName("X");
67 | MP_variable s(raw,TL); // storage at beginning of period
68 |
69 | MP_index p,r,t;
70 |
71 | MP_constraint
72 | limit(T), // capacity constraint
73 | balance(raw,TL); // raw material balance
74 |
75 |
76 | limit(T) = sum(prd(p), x(p,T)) <= m;
77 |
78 | balance(r,TL+1) =
79 | s(r,TL+1) == s(r,TL) - sum(prd(p), units(r,p)*x(p,TL));
80 |
81 | s.upperLimit(r,0) = istock(r);
82 |
83 |
84 | // MP_model::default_model.verbose();
85 |
86 | model.maximize(
87 | sum(T(t), sum(prd(p), profit(p,t)*x(p,t)) -
88 | sum(raw(r), scost(r)*s(r,t) )) +
89 | sum(raw(r), rvalue(r)*s(r,numT))
90 | );
91 |
92 | assert(model->getNumRows()==14);
93 | assert(model->getNumCols()==25);
94 | assert(model->getNumElements()==52);
95 | assert(model->getObjValue()>=79.3412 && model->getObjValue()<=79.3414);
96 |
97 | x.display();
98 | s.display();
99 | cout<<"Test ampl passed."<
6 |
7 | // Adapted from bid.gms from the GAMS model library:
8 | // http://www.gams.com/
9 |
10 | /* A company obtains a number of bids from vendors for the supply
11 | of a specified number of units of an item. Most of the submitted
12 | bids have prices that depend on the volume of business.
13 |
14 | Bracken, J, and McCormick, G P, Chapter 3. In Selected Applications of
15 | Nonlinear Programming. John Wiley and Sons, New York, 1968, pp. 28-36.
16 | */
17 |
18 | int main() {
19 | MP_model bid(new OsiCbcSolverInterface);
20 |
21 | enum { a, b, c, d, e, nbrV};
22 | const int numSegments = 5;
23 |
24 | MP_set V(nbrV); // vendors
25 | MP_set S(numSegments); // segments
26 |
27 | MP_subset<2> VS(V,S); // vendor bid possibilities
28 |
29 | VS.insert(a,0);
30 | VS.insert(b,0);
31 | VS.insert(b,1);
32 | VS.insert(b,2);
33 | VS.insert(b,3);
34 | VS.insert(c,0);
35 | VS.insert(d,0);
36 | VS.insert(e,0);
37 | VS.insert(e,1);
38 |
39 | MP_data setup(VS);
40 | MP_data price(VS);
41 | MP_data qmin (VS);
42 | MP_data qmax (VS);
43 |
44 | double req = 239600.48;
45 |
46 | setup(VS(a,0)) = 3855.84;
47 | setup(VS(b,0)) = 125804.84;
48 | setup(VS(c,0)) = 13456.00;
49 | setup(VS(d,0)) = 6583.98;
50 |
51 | price(VS(a,0)) = 61.150;
52 | price(VS(b,0)) = 68.099;
53 | price(VS(b,1)) = 66.049;
54 | price(VS(b,2)) = 64.099;
55 | price(VS(b,3)) = 62.119;
56 | price(VS(c,0)) = 62.190;
57 | price(VS(d,0)) = 72.488;
58 | price(VS(e,0)) = 70.150;
59 | price(VS(e,1)) = 68.150;
60 |
61 | qmin(VS(b,0)) = 22000;
62 | qmin(VS(b,1)) = 70000;
63 | qmin(VS(b,2)) = 100000;
64 | qmin(VS(b,3)) = 150000;
65 | qmin(VS(e,1)) = 42000;
66 |
67 | qmax(VS(a,0)) = 33000;
68 | qmax(VS(b,0)) = 70000;
69 | qmax(VS(b,1)) = 100000;
70 | qmax(VS(b,2)) = 150000;
71 | qmax(VS(b,3)) = 160000;
72 | qmax(VS(c,0)) = 165600;
73 | qmax(VS(d,0)) = 12000;
74 | qmax(VS(e,0)) = 42000;
75 | qmax(VS(e,1)) = 77000;
76 |
77 | setup(VS(V,S+1)) = setup(VS(V,S)) +
78 | qmax(VS(V,S))*(price(VS(V,S))-price(VS(V,S+1)));
79 |
80 | // setup(VS(V,S+1)) = setup(VS(V,S)) +
81 | // qmax(VS(V,S))*(price(VS(V,S))-price(VS(V,S+1)));
82 |
83 | setup.display("setup");
84 |
85 | MP_variable pl(VS); // purchase level
86 | MP_binary_variable plb(VS); // purchase decision
87 |
88 | MP_constraint
89 | demand, // demand constraint
90 | minpl(VS), // min purchase
91 | maxpl(VS), // max purchase
92 | oneonly(V);// at most one deal;
93 |
94 | demand() = req == sum( VS, pl(VS) );
95 |
96 | minpl(VS) = pl(VS) >= qmin(VS)*plb(VS);
97 |
98 | maxpl(VS) = pl(VS) <= qmax(VS)*plb(VS);
99 |
100 | oneonly(V) = sum(VS(V,S), plb(VS)) <= 1;
101 |
102 | bid.verbose();
103 |
104 | bid.minimize( sum(VS, price(VS)*pl(VS) + setup(VS)*plb(VS)) );
105 |
106 | assert(bid->getNumRows()==24);
107 | assert(bid->getNumCols()==18);
108 | assert(bid->getNumElements()==50);
109 | assert(bid->getObjValue()>=1.52100e+07 && bid->getObjValue()<=1.52102e+07);
110 |
111 | cout<<"Test bid passed."< M(I,I,I,I); // shared positions on the board;
25 |
26 | MP_index i,j,ii,jj;
27 |
28 | forall(
29 | I(i)*I(j)*I(ii)*I(jj).such_that(i==ii||j==jj || abs(i-ii)==abs(j-jj)),
30 | M.insert(i,j,ii,jj)
31 | );
32 |
33 | MP_variable
34 | b(I,I), // square occupied by a black Queen
35 | w(I,I), // square occupied by a white Queen
36 | tot; // total queens in each army;
37 |
38 | b.binary();
39 | w.binary();
40 |
41 | MP_constraint
42 | eq1(M), // keeps armies at peace
43 | eq2, // add up all the black queens
44 | eq3; // add up all the white queens;
45 |
46 |
47 | eq1(M(i,j,ii,jj)) = b(i,j) + w(ii,jj) <= 1;
48 |
49 | eq2() = tot() == sum(I(i)*I(j), b(i,j));
50 |
51 | eq3() = tot() == sum(I(i)*I(j), w(i,j));
52 |
53 | maximize(tot());
54 |
55 | MP_model::getDefaultModel()->writeMps("coex","mps",1.0);
56 |
57 | assert(MP_model::getDefaultModel()->getNumRows()==347);
58 | assert(MP_model::getDefaultModel()->getNumCols()==51);
59 | assert(MP_model::getDefaultModel()->getNumElements()==742);
60 | assert(MP_model::getDefaultModel()->getObjValue()==4);
61 |
62 | b.display("Black");
63 | w.display("White");
64 |
65 | cout<<"Test coex passed."<= xw(i,j);
64 |
65 | bw(j,i) = wb(j) >= xw(i,j);
66 |
67 | cw(s,i) = wc(s) >= xw(i,i+sh(s));
68 |
69 | dw(s,i) = wd(s) >= xw(i,i+rev(s,i));
70 |
71 | ab(i,j) = 1-wa(i) >= xb(i,j);
72 |
73 | bb(j,i) = 1-wb(j) >= xb(i,j);
74 |
75 | cb(s,i) = 1-wc(s) >= xb(i,i+sh(s));
76 |
77 | db(s,i) = 1-wd(s) >= xb(i,i+rev(s,i));
78 |
79 | eb() = tot() == sum(i*i(j), xb(i,j));
80 |
81 | ew() = tot() == sum(i*i(j), xw(i,j));
82 |
83 | xb.lowerLimit(0,0) = 1;
84 |
85 | maximize(tot());
86 |
87 | assert(MP_model::getDefaultModel()->getNumRows()==242);
88 | assert(MP_model::getDefaultModel()->getNumCols()==75);
89 | assert(MP_model::getDefaultModel()->getNumElements()==480);
90 | assert(MP_model::getDefaultModel()->getObjValue()==4);
91 |
92 | xb.display("Black");
93 | xw.display("White");
94 |
95 | cout<<"Test coexx passed."<getNumRows()==90);
73 | assert(MP_model::getDefaultModel()->getNumCols()==70);
74 | assert(MP_model::getDefaultModel()->getNumElements()==231);
75 | assert(MP_model::getDefaultModel()->getObjValue()==3);
76 |
77 | y.display("y");
78 | cross.display("cross");
79 |
80 | cout<<"Test cross passed."<
6 | #include
7 |
8 | class Paper : public MP_model {
9 | public:
10 | MP_set WIDTHS,PATTERNS;
11 | MP_data widths;
12 | MP_data demand;
13 | MP_data pattern;
14 | MP_variable use;
15 | MP_constraint demC;
16 |
17 | Paper(int numWidths) : MP_model(new OsiCbcSolverInterface),
18 | WIDTHS(numWidths), PATTERNS(numWidths),
19 | widths(WIDTHS), demand(WIDTHS),
20 | pattern(WIDTHS,PATTERNS), use(WIDTHS),
21 | demC(WIDTHS) {
22 |
23 | MP_index i,j;
24 |
25 | demC(i) = sum(WIDTHS(j), pattern(i,j)*use(j)) >= demand (i);
26 |
27 | setObjective( sum(WIDTHS(j), use(j)) );
28 | }
29 | };
30 |
31 | double knapsack(int n, double* a, const double* c, double b, double* pat) {
32 | MP_model KnapSack(new OsiCbcSolverInterface);
33 |
34 | MP_set I(n);
35 | MP_data A(I);
36 | MP_data C(I);
37 |
38 | A.value(a);
39 | C.value(c);
40 |
41 | A.display("A");
42 | C.display("C");
43 |
44 | MP_variable x(I);
45 | x.integer();
46 |
47 | MP_constraint constr;
48 |
49 | constr = sum(I, A(I)*x(I)) <= b;
50 | KnapSack.add(constr);
51 | KnapSack.maximize( sum(I, C(I)*x(I)) );
52 |
53 | x.display("x");
54 | for (int i=0; igetObjValue();
58 | }
59 |
60 | int main() {
61 | const int numWidths = 5;
62 | double tabDemand[] = {150, 96, 48, 108, 227};
63 | double tabWidth[] = {17, 21, 22.5, 24, 29.5};
64 | const double maxWidth = 94;
65 |
66 | MP_model Paper(new OsiCbcSolverInterface);
67 |
68 | MP_set WIDTHS(numWidths);
69 | MP_set PATTERNS(numWidths);
70 | MP_data width(WIDTHS);
71 | MP_data demand(WIDTHS);
72 | MP_data pattern(WIDTHS,PATTERNS);
73 |
74 | width.value(tabWidth);
75 | demand.value(tabDemand);
76 |
77 | for (int i=0; i= demand (i);
88 |
89 | Paper.add(demC);
90 | Paper.minimize( sum(WIDTHS(j), use(j)) );
91 |
92 | double pat[numWidths];
93 | double ob;
94 | do {
95 | ob = knapsack(numWidths, tabWidth, &Paper.rowPrice[demC.offset], maxWidth, pat);
96 |
97 | CoinPackedVector Pat;
98 | Pat.setFull(numWidths, pat);
99 |
100 | Paper->addCol(Pat,0,100,1);
101 | Paper->resolve();
102 | } while(ob>1.0001);
103 |
104 | Paper.minimize( sum(WIDTHS(j), use(j)) );
105 |
106 | assert(Paper->getNumRows()==5);
107 | assert(Paper->getNumCols()==5);
108 | assert(Paper->getNumElements()==5);
109 | assert(Paper->getObjValue()>=177.666 && Paper->getObjValue()<=177.667);
110 |
111 | cout<<"Test cuttingstock passed."<getObjValue();
90 | for (int jc=0; jczlbest);
100 | zlbest = std::max(zlbest,zl(0));
101 |
102 | double norm = 0.0;
103 | for (int jc=0; jcreset) {
116 | alpha = alpha/2.0;
117 | count = 1;
118 | } else if (improve == true) {
119 | count = 1;
120 | } else {
121 | count++;
122 | }
123 | }
124 |
125 | assert(zlbest>=222.99999 && zlbest<=223.00001);
126 |
127 | vector pknap;
128 |
129 | for (int k=0; kx.level(q) == 1) cout<
6 |
7 | // M A G I C Power Scheduling Problem
8 | /* A number of power stations are committed to meet demand for a particular
9 | day. three types of generators having different operating characteristics
10 | are available. Generating units can be shut down or operate between
11 | minimum and maximum output levels. Units can be started up or closed down
12 | in every demand block.
13 |
14 | Reference: R E Day and H P Williams, MAGIC: The design and use of an
15 | interactive modeling language for mathematical programming,
16 | Department Business Studies, University of Edinburgh, Edinburgh,
17 | UK, February 1982.
18 |
19 | H P Williams, Model Building in Mathematical Programming, Wiley,
20 | New York, 1978.
21 | */
22 |
23 | int main() {
24 | enum {t12pm_6am, t6am_9am, t9am_3pm, t3pm_6pm, t6pm_12pm, numT};
25 | enum {type_1, type_2, type_3, numG};
26 |
27 | MP_set T(numT); T.cyclic();
28 | MP_set G(numG);
29 |
30 | MP_data dem(T); // demand (1000mw)
31 | dem(t12pm_6am) = 15;
32 | dem(t6am_9am) = 30;
33 | dem(t9am_3pm) = 25;
34 | dem(t3pm_6pm) = 40;
35 | dem(t6pm_12pm) = 27;
36 |
37 | MP_data dur(T); // duration (hours)
38 | dur(t12pm_6am) = 6;
39 | dur(t6am_9am) = 3;
40 | dur(t9am_3pm) = 6;
41 | dur(t3pm_6pm) = 3;
42 | dur(t6pm_12pm) = 6;
43 |
44 | MP_data
45 | min_pow(G),
46 | max_pow(G),
47 | cost_min(G),
48 | cost_inc(G),
49 | start(G),
50 | number(G);
51 |
52 | min_pow(type_1) = 0.85; max_pow(type_1) = 2.0;
53 | min_pow(type_2) = 1.25; max_pow(type_2) = 1.75;
54 | min_pow(type_3) = 1.5; max_pow(type_3) = 4.0;
55 |
56 | cost_min(type_1) = 1000; cost_inc(type_1) = 2.0;
57 | cost_min(type_2) = 2600; cost_inc(type_2) = 1.3;
58 | cost_min(type_3) = 3000; cost_inc(type_3) = 3.0;
59 |
60 | start(type_1) = 2000; number(type_1) = 12;
61 | start(type_2) = 1000; number(type_2) = 10;
62 | start(type_3) = 500; number(type_3) = 5;
63 |
64 | MP_data
65 | peak, // peak power (1000 mw)
66 | ener(T), // energy demand in load block (1000mwh)
67 | tener, // total energy demanded (1000mwh)
68 | lf; // load factor
69 |
70 | MP_index i,j;
71 |
72 | peak() = maximum(T(i), dem(i));
73 |
74 | ener(i) = dur(i)*dem(i);
75 |
76 | tener() = sum(T(i), ener(i));
77 |
78 | lf() = tener()/(peak() * 24);
79 |
80 | peak.display();
81 | tener.display();
82 | lf.display();
83 | ener.display("ener");
84 |
85 | MP_variable
86 | x(G,T), // generator output (1000mw)
87 | n(G,T), // number of generators in use
88 | s(G,T); // number of generators started up
89 |
90 | n.integer();
91 | n.upperLimit(j,i) = number(j);
92 | n.upperLimit.display("n upper");
93 |
94 | MP_constraint
95 | pow(T), // demand for power (1000mw)
96 | res(T), // spinning reserve requirements (1000mw)
97 | st(G,T), // start_up definition
98 | minu(G,T), // minimum generation level (1000mw)
99 | maxu(G,T); // maximum generation level (1000mw)
100 |
101 | pow(i) = sum(G(j), x(j,i)) >= dem(i);
102 |
103 | res(i) = sum(G(j), max_pow(j)*n(j,i)) >= 1.15*dem(i);
104 |
105 | st(j,i) = s(j,i) >= n(j,i) - n(j,i-1);
106 |
107 | minu(j,i) = x(j,i) >= min_pow(j)*n(j,i);
108 |
109 | maxu(j,i) = x(j,i) <= max_pow(j)*n(j,i);
110 |
111 | MP_expression cost; // total operating cost (l)
112 | cost = sum(G(j)*T(i),
113 | dur(i)* cost_min(j)*n(j,i) + start(j)*s(j,i) +
114 | 1000*dur(i)*cost_inc(j)*(x(j,i)-min_pow(j)*n(j,i)) );
115 |
116 |
117 | MP_model::getDefaultModel().setSolver(new OsiCbcSolverInterface);
118 | MP_model::getDefaultModel().verbose();
119 |
120 | minimize(cost);
121 |
122 | assert(MP_model::getDefaultModel()->getNumRows()==55);
123 | assert(MP_model::getDefaultModel()->getNumCols()==45);
124 | assert(MP_model::getDefaultModel()->getNumElements()==135);
125 | assert(MP_model::getDefaultModel()->getObjValue()>=988539 && MP_model::getDefaultModel()->getObjValue()<=988541);
126 |
127 |
128 | x.display("x");
129 | n.display("n");
130 | s.display("s");
131 | const int TSize=T.size();
132 | double **rep = new double *[TSize];
133 | for(int cnt=0;cnt c(l,l,l); // neighbouring blocks related to extraction feasibility
59 | MP_subset<3> d(l,l,l); // complete set of block identifiers
60 |
61 | MP_data li(k), // lead for i / (se,sw) = 1 /
62 | lj(k), // lead for j / ("ne",se) = 1 /
63 | cost(l); // block extraction cost / 1=3000, 2=6000, 3=8000, 4=10000 /
64 |
65 | li(se) = 1;
66 | li(sw) = 1;
67 | lj(ne) = 1;
68 | lj(se) = 1;
69 |
70 | cost(0) = 3000;
71 | cost(1) = 6000;
72 | cost(2) = 8000;
73 | cost(3) =10000;
74 |
75 | double value = 200000;
76 |
77 | forall(l*l(i)*l(j).such_that( l+i= x(l+1,i,j);
96 |
97 | x.upperLimit(l,i,j) = 1;
98 |
99 | maximize( sum(d(l,i,j), (conc(l,i,j)*value/100 - cost(l))*x(l,i,j)) );
100 |
101 | assert(MP_model::getDefaultModel()->getNumRows()==56);
102 | assert(MP_model::getDefaultModel()->getNumCols()==64);
103 | assert(MP_model::getDefaultModel()->getNumElements()==112);
104 | assert(MP_model::getDefaultModel()->getObjValue()>=17500 && MP_model::getDefaultModel()->getObjValue()<=17500);
105 |
106 |
107 | x.display("x");
108 | cout<<"Test mine passed."<
3 | #include
4 | using namespace flopc;
5 | using namespace std;
6 |
7 | void MultiProduct(
8 | MP_set& Cities,
9 | MP_set& Products,
10 | MP_subset<3>& Routes,
11 | MP_subset<2>& Suppliers,
12 | MP_subset<2>& Customers,
13 | MP_subset<2>& Connections,
14 | MP_data& supply,
15 | MP_data& demand,
16 | double& limit,
17 | MP_data& cost
18 | ) {
19 | MP_index p,o,d;
20 | MP_variable trans(Routes);
21 |
22 | MP_constraint sup(Suppliers);
23 | MP_constraint dem(Customers);
24 | MP_constraint lim(Connections);
25 |
26 | sup(Suppliers(p,o)) =
27 | sum(Routes(p,o,d), trans(Routes(p,o,d))) <= supply(Suppliers(p,o));
28 |
29 | dem(Customers(p,d)) =
30 | sum(Routes(p,o,d), trans(Routes(p,o,d))) >= demand(Customers(p,d));
31 |
32 | lim(Connections(o,d)) =
33 | sum(Routes(p,o,d), trans(Routes(p,o,d))) <= limit;
34 |
35 | minimize( sum(Routes(p,o,d), cost(Routes(p,o,d)) * trans(Routes(p,o,d))) );
36 |
37 | assert(MP_model::getDefaultModel()->getNumRows()==41);
38 | assert(MP_model::getDefaultModel()->getNumCols()==18);
39 | assert(MP_model::getDefaultModel()->getNumElements()==54);
40 |
41 | trans.display("solution");
42 | }
43 |
44 | double random(double min, double max) {
45 | return min + (max-min)*(rand()/(RAND_MAX+0.0));
46 | }
47 |
48 | int main() {
49 | MP_model::getDefaultModel().setSolver(new OsiCbcSolverInterface);
50 | MP_model::getDefaultModel().verbose();
51 | enum {Godiva,Neuhaus,Leonidas,nbrProducts};
52 | enum {Brussels,Amsterdam,Antwerpen,Paris,Milan,Cassis,Bonn,Madrid,Bergen,
53 | London,nbrCities};
54 |
55 | MP_set Cities(nbrCities);
56 | MP_set Products(nbrProducts);
57 | MP_subset<3> Routes(Products,Cities,Cities);
58 |
59 | Routes.insert(Godiva,Brussels,Paris);
60 | Routes.insert(Godiva,Brussels,Bonn);
61 | Routes.insert(Godiva,Amsterdam,London);
62 | Routes.insert(Godiva,Amsterdam,Milan);
63 | Routes.insert(Godiva,Antwerpen,Madrid);
64 | Routes.insert(Godiva,Antwerpen,Bergen);
65 |
66 | Routes.insert(Neuhaus,Brussels,Madrid);
67 | Routes.insert(Neuhaus,Brussels,Bergen);
68 | Routes.insert(Neuhaus,Amsterdam,Madrid);
69 | Routes.insert(Neuhaus,Amsterdam,Cassis);
70 | Routes.insert(Neuhaus,Antwerpen,Paris);
71 | Routes.insert(Neuhaus,Antwerpen,Bonn);
72 |
73 | Routes.insert(Leonidas,Brussels,Bonn);
74 | Routes.insert(Leonidas,Brussels,Milan);
75 | Routes.insert(Leonidas,Amsterdam,Paris);
76 | Routes.insert(Leonidas,Amsterdam,Cassis);
77 | Routes.insert(Leonidas,Antwerpen,London);
78 | Routes.insert(Leonidas,Antwerpen,Bergen);
79 |
80 | cout<<"Number of Routes = "< Suppliers(Products,Cities);
83 | MP_subset<2> Customers(Products,Cities);
84 | MP_subset<2> Connections(Cities,Cities);
85 |
86 | MP_index p,o,d;
87 |
88 | // Set "projections"
89 | Suppliers(p,o) <<= Routes(p, o, MP_index::Any);
90 | Customers(p,d) <<= Routes(p, MP_index::Any, d);
91 | Connections(o,d) <<= Routes(MP_index::Any, o, d);
92 |
93 | cout< $1.output
5 | grep -i assert $1.output
6 | grep passed $1.output
7 |
--------------------------------------------------------------------------------
/FlopCpp/examples/stampl.cpp:
--------------------------------------------------------------------------------
1 | // $Id$
2 | #include "flopc.hpp"
3 | using namespace flopc;
4 | using namespace std;
5 | #include "OsiCbcSolverInterface.hpp"
6 |
7 | /* FLOPC++ implementation of a financial planning and control model from
8 | "StAMPL: A filtration-oriented modeling toll for stochastic programming" by Fourer and Lopes
9 | The FLOPC++ formulation is in many aspects similar to the StAMPL solution, it is however different in
10 | that the scenario generation is recursive and is not separated from the model.
11 |
12 | The formulation could off course be improoved by accepting data (4 and 80) as parameters, etc.. But it shows
13 | that multistage stochastic programs can conviently be formulated with FLOPC++ and that extensions or tools built
14 | on top of FLOPC++ could make the modelling of this type of models even easier
15 | */
16 |
17 | enum { STOCKS, BONDS, numINSTR};
18 |
19 | class Stage {
20 | public:
21 | Stage(Stage* p, int numINSTR, double probability=0.5) : parent(p), INSTR(numINSTR), Buy(INSTR),
22 | pathprob(probability) {
23 | if (parent != 0) pathprob *= parent->pathprob;
24 | }
25 |
26 | MP_set INSTR;
27 | MP_variable Buy;
28 | MP_expression Final_wealth;
29 |
30 | Stage* parent;
31 | vector children;
32 | double pathprob;
33 | };
34 |
35 | class Stage_1 : public Stage {
36 | public:
37 | MP_data initial_wealth;
38 | MP_constraint InvestAll;
39 |
40 | Stage_1(int numINSTR, double w, MP_data& Good, MP_data& Bad, int n);
41 | };
42 |
43 | class Stage_i : public Stage {
44 | public:
45 | MP_constraint ReinvestAll;
46 |
47 | Stage_i(int numINSTR, MP_data& Return, int n, Stage* p, MP_data& Good, MP_data& Bad);
48 | };
49 |
50 | class Stage_n : public Stage {
51 | public:
52 | MP_variable Shortage, Overage;
53 | MP_constraint ReinvestAll;
54 |
55 | Stage_n(int numINSTR, MP_data& Return, double goal, Stage* p) : Stage(p,numINSTR) {
56 | ReinvestAll() = sum(INSTR, parent->Buy(INSTR) * Return(INSTR)) == goal - Shortage() + Overage();
57 |
58 | Final_wealth = pathprob*(Overage() - 4*Shortage());
59 | }
60 | };
61 |
62 |
63 | Stage_1::Stage_1(int numINSTR, double w, MP_data& Good, MP_data& Bad, int n) : Stage(0, numINSTR, 1) {
64 | initial_wealth() = w;
65 | InvestAll() = sum(INSTR, Buy(INSTR)) == initial_wealth();
66 |
67 | children.push_back(new Stage_i(numINSTR, Good, n-1, this, Good, Bad));
68 | children.push_back(new Stage_i(numINSTR, Bad, n-1, this, Good, Bad));
69 |
70 | maximize(children[0]->Final_wealth + children[1]->Final_wealth);
71 | }
72 |
73 | Stage_i::Stage_i(int numINSTR, MP_data& Return, int n, Stage* p, MP_data& Good, MP_data& Bad) : Stage(p, numINSTR) {
74 |
75 | ReinvestAll() = sum(INSTR, parent->Buy(INSTR) * Return(INSTR)) == sum(INSTR, Buy(INSTR));
76 |
77 | if (n==2) {
78 | children.push_back(new Stage_n(numINSTR, Good, 80, this));
79 | children.push_back(new Stage_n(numINSTR, Bad, 80, this));
80 | } else {
81 | children.push_back(new Stage_i(numINSTR, Good, n-1, this, Good, Bad));
82 | children.push_back(new Stage_i(numINSTR, Bad, n-1, this, Good, Bad));
83 | }
84 |
85 | Final_wealth = children[0]->Final_wealth + children[1]->Final_wealth;
86 | }
87 |
88 | int main() {
89 | const int numStages = 4;
90 | MP_model::getDefaultModel().setSolver(new OsiCbcSolverInterface);
91 | MP_model::getDefaultModel().verbose();
92 |
93 | MP_set INSTR(numINSTR);
94 | MP_data GoodReturn(INSTR);
95 | MP_data BadReturn(INSTR);
96 |
97 | GoodReturn(STOCKS) = 1.25;
98 | GoodReturn(BONDS) = 1.14;
99 | BadReturn(STOCKS) = 1.06;
100 | BadReturn(BONDS) = 1.12;
101 |
102 | Stage_1 M(numINSTR, 55, GoodReturn, BadReturn, numStages);
103 | M.Buy.display();
104 | }
105 |
106 | // part of the expected output
107 | // FlopCpp: Number of constraint blocks: 15
108 | // FlopCpp: Number of individual constraints: 15
109 | // FlopCpp: Number of variable blocks: 23
110 | // FlopCpp: Number of individual variables: 30
111 | // FlopCpp: Number of non-zeroes (including rhs): 67
112 | // FlopCpp: Generation time: 0
113 | // FlopCpp: Optimal obj. value = -1.51408
114 | // FlopCpp: Solver(m, n, nz) = 15 30 58
115 | // 0 41.4793
116 | // 1 13.5207
117 |
118 |
--------------------------------------------------------------------------------
/FlopCpp/examples/stampl2.cpp:
--------------------------------------------------------------------------------
1 | // $Id$
2 | #include "flopc.hpp"
3 | using namespace flopc;
4 | using namespace std;
5 | #include "OsiCbcSolverInterface.hpp"
6 |
7 | /* FLOPC++ implementation of a financial planning and control model from
8 | "StAMPL: A filtration-oriented modeling toll for stochastic programming" by Fourer and Lopes
9 | */
10 |
11 |
12 | main() {
13 | MP_model::getDefaultModel().setSolver(new OsiCbcSolverInterface);
14 | MP_model::getDefaultModel().verbose();
15 |
16 | enum { STOCKS, BONDS, numINSTR};
17 | const int numStages = 3;
18 |
19 | MP_set INSTR(numINSTR);
20 | MP_stage T(numStages);
21 |
22 | MP_stochastic_data Return(T,INSTR);
23 |
24 | MP_variable Buy(T,INSTR);
25 | MP_variable Shortage, Overage;
26 |
27 | MP_constraint InvestAll;
28 | MP_constraint ReinvestAll(T);
29 | MP_constraint Goal;
30 |
31 | double initial_wealth = 55;
32 | double goal = 80;
33 |
34 | //---------------------------------
35 | MP_data GoodReturn(INSTR);
36 | MP_data BadReturn(INSTR);
37 |
38 | GoodReturn(STOCKS) = 1.25; GoodReturn(BONDS) = 1.14;
39 | BadReturn(STOCKS) = 1.06; BadReturn(BONDS) = 1.12;
40 |
41 | Return(T,INSTR) = 1.33;
42 |
43 | // Return(T,INSTR) = GoodReturn(INSTR).probability(0.5);
44 | // Return(T,INSTR) = BadReturn(INSTR).probability(0.5);
45 | //---------------------------------
46 |
47 | InvestAll() = sum(INSTR, Buy(0,INSTR)) == initial_wealth;
48 |
49 | ReinvestAll(T+1) = sum(INSTR, Buy(T,INSTR) * Return(T,INSTR)) == sum(INSTR, Buy(T+1,INSTR));
50 |
51 | Goal() = sum(INSTR, Buy(T.last(),INSTR) * Return(T.last(),INSTR)) == goal - Shortage() + Overage();
52 |
53 | maximize( Overage() - 4*Shortage() );
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/FlopCpp/examples/stochbenders.cpp:
--------------------------------------------------------------------------------
1 | // $Id$
2 | #include "flopc.hpp"
3 | using namespace flopc;
4 | using namespace std;
5 | #include "OsiClpSolverInterface.hpp"
6 |
7 | /* Benders decomposition for a simple transportation problem
8 | with stochastic demands. For details see: Erwin Kalvelagen:
9 | "Benders decomposition for stochastic programming with GAMS"
10 | (www.gams.com/~erwin/stochbenders.pdf)
11 | */
12 |
13 |
14 | int main() {
15 | const int numScenarios = 3;
16 | const int numFactories = 3;
17 | const int numDistributionCenters = 5;
18 | MP_set i(numFactories), j(numDistributionCenters);
19 |
20 | MP_data
21 | capacity(i),
22 | transcost(i,j);
23 |
24 | transcost(0,0) = 2.49; transcost(1,0) = 1.46; transcost(2,0) = 3.26;
25 | transcost(0,1) = 5.21; transcost(1,1) = 2.54; transcost(2,1) = 3.08;
26 | transcost(0,2) = 3.76; transcost(1,2) = 1.84; transcost(2,2) = 2.60;
27 | transcost(0,3) = 4.85; transcost(1,3) = 1.86; transcost(2,3) = 3.76;
28 | transcost(0,4) = 2.07; transcost(1,4) = 4.76; transcost(2,4) = 4.45;
29 |
30 | capacity(0) = 500;
31 | capacity(1) = 450;
32 | capacity(2) = 650;
33 |
34 | const double prodcost = 14;
35 | const double price = 24;
36 | const double wastecost = 4;
37 |
38 | const double Demand[numScenarios][numDistributionCenters] =
39 | {{150,100,250,300,600},
40 | {160,120,270,325,700},
41 | {170,135,300,350,800}};
42 |
43 | const double prob[numScenarios] = {0.25,0.5,0.25};
44 |
45 | ///// Master problem /////////////////////////////////////////////
46 |
47 | MP_model masterproblem(new OsiClpSolverInterface);
48 |
49 | MP_variable
50 | theta,
51 | ship(i,j),
52 | product(i),
53 | slackproduct(i),
54 | received(j);
55 |
56 | MP_constraint
57 | production(i),
58 | receive(j),
59 | prodcap(i);
60 |
61 | production(i) = product(i) == sum(j,ship(i,j));
62 | receive(j) = received(j) == sum(i,ship(i,j));
63 | prodcap(i) = product(i) + slackproduct(i) == capacity(i);
64 |
65 | masterproblem.minimize( sum(i*j,transcost(i,j)*ship(i,j)) +
66 | sum(i, prodcost*product(i)) + theta() );
67 |
68 | ///// Sub problem ///////////////////////////////////////////////
69 |
70 | MP_model subproblem(new OsiClpSolverInterface);
71 |
72 | MP_variable
73 | sales(j),
74 | waste(j),
75 | slacksales(j);
76 |
77 | MP_constraint
78 | selling(j),
79 | selmax(j);
80 |
81 | selling(j) = sales(j) + waste(j) == 0.0;
82 | selmax(j) = sales(j) + slacksales(j) == 0.0;
83 |
84 | subproblem.minimize( sum(j, wastecost*waste(j)) - sum(j, price*sales(j)) );
85 |
86 | ///// Benders algorithm //////////////////////////////////////////
87 |
88 | masterproblem->setColLower( theta().getColumn(), -masterproblem->getInfinity());
89 |
90 | double lowerbound = -masterproblem->getInfinity();
91 | double upperbound = masterproblem->getInfinity();
92 | double objmaster = 0.0;
93 |
94 | int kk;
95 | for (kk=0; kk<25; kk++) { // max 25 iterations
96 | double cutconst = 0.0;
97 | MP_data cutcoeff(j);
98 |
99 | double objsub = 0.0;
100 | received.display("received");
101 | for (int jj=0; jjsetRowBounds( selling(jj), received.level(jj), received.level(jj));
103 | }
104 | for (int s=0; ssetRowBounds( selmax(j), Demand[s][j], Demand[s][j]);
107 | }
108 | subproblem->resolve();
109 | objsub += prob[s]*subproblem->getObjValue();
110 | for (int j=0; j= cutconst + sum(j, cutcoeff(j)*received(j)) );
125 |
126 | masterproblem->resolve();
127 | ship.display("ship");
128 |
129 | lowerbound = masterproblem->getObjValue();
130 | objmaster = lowerbound - theta.level();
131 | }
132 | assert(kk<25);
133 |
134 | // Expected solution:
135 | // ship
136 | // 0 0 0
137 | // 0 1 0
138 | // 0 2 0
139 | // 0 3 0
140 | // 0 4 500
141 | // 1 0 150
142 | // 1 1 0
143 | // 1 2 0
144 | // 1 3 300
145 | // 1 4 0
146 | // 2 0 0
147 | // 2 1 100
148 | // 2 2 270
149 | // 2 3 0
150 | // 2 4 100
151 |
152 | cout<<"Test stochbenders passed."<
6 | #include
7 | #include
8 | #include
9 |
10 | /**/
11 |
12 |
13 | int main() {
14 | MP_model::getDefaultModel().setSolver(new OsiCbcSolverInterface);
15 |
16 | const int p = 3;
17 |
18 | MP_set J(p*p);
19 | MP_set K(p);
20 | MP_subset<3> F(J,J,J);
21 |
22 | std::string fname = "fixed.dat";
23 | std::ifstream file(fname.c_str());
24 |
25 | int ival,jval,kval;
26 |
27 | while (file>>ival>>jval>>kval) {
28 | F.insert(ival-1,jval-1,kval-1);
29 | }
30 | file.close();
31 |
32 | MP_binary_variable x(J,J,J);
33 |
34 | MP_constraint
35 | rows(J,J),
36 | cols(J,J),
37 | nums(J,J),
38 | squares(K,K,J),
39 | preselected(F);
40 |
41 | MP_index i,j,k,m,n;
42 |
43 | rows(i,j) = sum(J(k), x(i,j,k)) == 1;
44 | cols(j,k) = sum(J(i), x(i,j,k)) == 1;
45 | nums(i,k) = sum(J(j), x(i,j,k)) == 1;
46 |
47 | squares(m,n,k) = sum(K(i)*K(j), x(m*p+Constant(i),n*p+Constant(j),k)) == 1;
48 |
49 | preselected(F(i,j,k)) = x(i,j,k) == 1;
50 |
51 | // minimize(sum(J(i)*J(j)*J(k),x(i,j,k)));
52 |
53 | minimize(x(0,0,0));
54 |
55 | for (int i=0; i<9; i++) {
56 | for (int j=0; j<9; j++) {
57 | for (int k=0; k<9; k++) {
58 | if (x.level(i,j,k)==1) {
59 | cout<= d(D) ;
33 |
34 | def_y(S,D) = d(D)*y(S,D) >= x(S,D);
35 |
36 | add(supply); add(demand); add(def_y);
37 |
38 | setObjective( sum(S*D, y(S,D)) );
39 |
40 | }
41 | };
42 |
43 | int main() {
44 | double stab_1[6] = {5,5,6,6,6,6};
45 | double dtab_1[4] = {4, 7, 10, 11};
46 | double stab_2[7] = {9,9,10,12,12,12,16};
47 | double dtab_2[5] = {6, 14, 17, 21, 22};
48 |
49 | Tap first_instance(6,4);
50 | Tap second_instance(7,5);
51 |
52 | first_instance.s.value(stab_1);
53 | first_instance.d.value(dtab_1);
54 |
55 | second_instance.s.value(stab_2);
56 | second_instance.d.value(dtab_2);
57 |
58 | first_instance.minimize();
59 |
60 | assert(first_instance->getNumRows()==34);
61 | assert(first_instance->getNumCols()==48);
62 | assert(first_instance->getNumElements()==96);
63 | assert(first_instance->getObjValue()>=7 && first_instance->getObjValue()<=7);
64 |
65 |
66 | first_instance.x.display("Solution of first instance (x)");
67 | first_instance.y.display("Solution of first instance (y)");
68 |
69 | second_instance.minimize();
70 |
71 | assert(second_instance->getNumRows()==47);
72 | assert(second_instance->getNumCols()==70);
73 | assert(second_instance->getNumElements()==140);
74 | assert(second_instance->getObjValue()>=9 && second_instance->getObjValue()<=9);
75 |
76 | second_instance.x.display("Solution of second instance");
77 | cout<<"Test tap passed."<
6 |
7 | int main() {
8 | MP_model::getDefaultModel().setSolver(new OsiClpSolverInterface);
9 | enum {seattle, sandiego, numS};
10 | enum {newyork, chicago, topeka,numD};
11 |
12 | MP_set S(numS); // Sources
13 | MP_set D(numD); // Destinations
14 | MP_subset<2> Link(S,D); // Transportation links (sparse subset of S*D)
15 |
16 | Link.insert(seattle,newyork);
17 | Link.insert(seattle,chicago);
18 | Link.insert(sandiego,chicago);
19 | Link.insert(sandiego,topeka);
20 |
21 | MP_data SUPPLY(S);
22 | MP_data DEMAND(D);
23 |
24 | SUPPLY(seattle)=350; SUPPLY(sandiego)=600;
25 | DEMAND(newyork)=325; DEMAND(chicago)=300; DEMAND(topeka)=275;
26 |
27 | MP_data COST(Link);
28 |
29 | COST(Link(seattle,newyork)) = 2.5;
30 | COST(Link(seattle,chicago)) = 1.7;
31 | COST(Link(sandiego,chicago))= 1.8;
32 | COST(Link(sandiego,topeka)) = 1.4;
33 |
34 | COST(Link) = 90 * COST(Link) / 1000.0;
35 |
36 | MP_variable x(Link);
37 | x.display("...");
38 |
39 | MP_constraint supply(S);
40 | MP_constraint demand(D);
41 |
42 | supply.display("...");
43 |
44 | supply(S) = sum( Link(S,D), x(Link) ) <= SUPPLY(S);
45 | demand(D) = sum( Link(S,D), x(Link) ) >= DEMAND(D);
46 |
47 | cout<<"Here"<getNumRows()==5);
51 | assert(MP_model::getDefaultModel()->getNumCols()==4);
52 | assert(MP_model::getDefaultModel()->getNumElements()==8);
53 | assert(MP_model::getDefaultModel()->getObjValue()>=156.14 && MP_model::getDefaultModel()->getObjValue()<=156.16);
54 |
55 | x.display("Optimal solution:");
56 | supply.display("Supply dual solution");
57 | cout<<"Test transport passed."<
7 | #include "flopc.hpp"
8 | using namespace flopc;
9 | using namespace std;
10 |
11 | int main() {
12 | const int numJ = 4;
13 | const int numT = 10;
14 |
15 | MP_set J(numJ),T(numT);
16 | MP_data D(J);
17 |
18 | D(0) = 3;
19 | D(1) = 4;
20 | D(2) = 2;
21 | D(3) = 2;
22 |
23 | MP_variable s(J);
24 | MP_binary_variable delta(J,T);
25 |
26 | MP_index t,j;
27 | MP_model M(new OsiCbcSolverInterface);
28 | MP_constraint C2_20, C2_30, C3(J), C4(J);
29 |
30 | C2_20() = s(2) >= D(0) + s(0);
31 | C2_30() = s(3) >= D(0) + s(0);
32 |
33 | C3(J) = sum( T(t).such_that(t <= numT-D(j)), (t+1)*delta(j,t) ) == s(j);
34 |
35 | C4(J) = sum( T(t).such_that(t <= numT-D(j)), delta(j,t) ) == 1;
36 |
37 | s.upperLimit(j) = numT-D(j);
38 |
39 | M.minimize_max( J, s(J)+D(J) );
40 |
41 | assert(M->getNumRows()==14);
42 | assert(M->getNumCols()==45);
43 | assert(M->getNumElements()==80);
44 | assert(M->getObjValue()>=6 && M->getObjValue()==6);
45 |
46 | s.display("s");
47 | cout<<"Test xbsl passed."<
10 | #include
11 |
12 | #include "MP_constraint.hpp"
13 | #include "MP_expression.hpp"
14 | #include "MP_model.hpp"
15 | #include "MP_constant.hpp"
16 | #include "MP_data.hpp"
17 |
18 | using namespace flopc;
19 | using namespace std;
20 |
21 |
22 | void MP_constraint::operator=(const Constraint &v) {
23 | left = v.left;
24 | right = v.right;
25 | sense = v.sense;
26 | }
27 |
28 | int MP_constraint::row_number() const {
29 | int i1 = S1.check(I1->evaluate());
30 | int i2 = S2.check(I2->evaluate());
31 | int i3 = S3.check(I3->evaluate());
32 | int i4 = S4.check(I4->evaluate());
33 | int i5 = S5.check(I5->evaluate());
34 |
35 | if (i1==outOfBound || i2==outOfBound || i3==outOfBound ||
36 | i4==outOfBound || i5==outOfBound) {
37 | return outOfBound;
38 | } else {
39 | return offset + f(I1->evaluate(),I2->evaluate(),I3->evaluate(),
40 | I4->evaluate(),I5->evaluate());
41 | }
42 | }
43 |
44 | double MP_constraint::price(int i1, int i2, int i3, int i4, int i5) const {
45 | return M->rowPrice[offset + f(i1,i2,i3,i4,i5)];
46 | }
47 |
48 | MP_constraint::MP_constraint(
49 | const MP_set_base &s1,
50 | const MP_set_base &s2,
51 | const MP_set_base &s3,
52 | const MP_set_base &s4,
53 | const MP_set_base &s5) :
54 | RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
55 | // pprice(MP_data(d1->getSet(),d2->getSet(),d3->getSet(),
56 | // d4->getSet(),d5->getSet())),
57 | M(MP_model::current_model),
58 | offset(-1),
59 | S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
60 | I1(0),I2(0),I3(0),I4(0),I5(0)
61 | {
62 | MP_model::current_model->add(*this);
63 | }
64 |
65 | void MP_constraint::coefficients(GenerateFunctor& f) {
66 | f.setConstraint(this);
67 |
68 | vector v;
69 |
70 | if (I1.operator->()!=0) {
71 | left->generate(S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5).such_that(B),v,f,1.0);
72 | right->generate(S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5).such_that(B),v,f,-1.0);
73 | } else {
74 | cout<<"FlopCpp Warning: Constraint declared but not defined."<& v) {
79 | if (left.operator->()!=0) {
80 | left->insertVariables(v);
81 | }
82 | if (right.operator->()!=0) {
83 | right->insertVariables(v);
84 | }
85 | }
86 |
87 | void MP_constraint::display(string s) const {
88 | cout<=0) {
90 | for (int i=offset; ibl[i]<<" "<rowActivity[i]<<" "<bu[i]<<" "<rowPrice[i]<
10 |
11 | #include "MP_data.hpp"
12 | #include "MP_domain.hpp"
13 | #include "MP_index.hpp"
14 | #include "MP_set.hpp"
15 | #include "MP_constant.hpp"
16 | #include "MP_expression.hpp"
17 |
18 | using namespace flopc;
19 | using namespace std;
20 |
21 | double MP_data::outOfBoundData = 0;
22 |
23 | const DataRef& DataRef::operator=(const Constant& c) {
24 | C = c;
25 | ((D->S1(I1)*D->S2(I2)*D->S3(I3)*D->S4(I4)*D->S5(I5)).such_that(B)).Forall(this);
26 | return *this;;
27 | }
28 |
29 | const DataRef& DataRef::operator=(const DataRef& r) {
30 | return operator=(Constant(const_cast(&r)));
31 | }
32 |
33 | void DataRef::operator()() const {
34 | evaluate_lhs(C->evaluate());
35 | }
36 |
37 | DataRef& DataRef::such_that(const MP_boolean& b) {
38 | B = b;
39 | return *this;
40 | }
41 |
42 |
43 | double DataRef::evaluate() const {
44 | int i1 = D->S1.check(I1->evaluate());
45 | int i2 = D->S2.check(I2->evaluate());
46 | int i3 = D->S3.check(I3->evaluate());
47 | int i4 = D->S4.check(I4->evaluate());
48 | int i5 = D->S5.check(I5->evaluate());
49 |
50 | int i = D->f(i1,i2,i3,i4,i5);
51 | if ( i == outOfBound ) {
52 | return 0;
53 | } else {
54 | return D->v[i];
55 | }
56 | }
57 |
58 |
59 |
60 | int DataRef::getStage() const {
61 | int i1 = D->S1.checkStage(I1->evaluate());
62 | int i2 = D->S2.checkStage(I2->evaluate());
63 | int i3 = D->S3.checkStage(I3->evaluate());
64 | int i4 = D->S4.checkStage(I4->evaluate());
65 | int i5 = D->S5.checkStage(I5->evaluate());
66 |
67 | int stage = 0;
68 | if (i1>stage) stage = i1;
69 | if (i2>stage) stage = i2;
70 | if (i3>stage) stage = i3;
71 | if (i4>stage) stage = i4;
72 | if (i5>stage) stage = i5;
73 |
74 | // might need to add outofbound check here
75 | return stage+stochastic;
76 | }
77 |
78 |
79 | void DataRef::evaluate_lhs(double v) const {
80 | int i1 = D->S1.check(I1->evaluate());
81 | int i2 = D->S2.check(I2->evaluate());
82 | int i3 = D->S3.check(I3->evaluate());
83 | int i4 = D->S4.check(I4->evaluate());
84 | int i5 = D->S5.check(I5->evaluate());
85 |
86 | int i = D->f(i1,i2,i3,i4,i5);
87 | if (i != outOfBound) {
88 | D->v[i] = v;
89 | }
90 | }
91 |
92 | void MP_data::operator()() const {
93 | if (&S1!=&MP_set::getEmpty()) cout << i1.evaluate() << " ";
94 | if (&S2!=&MP_set::getEmpty()) cout << i2.evaluate() << " ";
95 | if (&S3!=&MP_set::getEmpty()) cout << i3.evaluate() << " ";
96 | if (&S4!=&MP_set::getEmpty()) cout << i4.evaluate() << " ";
97 | if (&S5!=&MP_set::getEmpty()) cout << i5.evaluate() << " ";
98 | cout<<" "<(this));
20 | }
21 |
22 | class Functor_conditional : public Functor {
23 | public:
24 | Functor_conditional(const Functor* f, const std::vector & condition)
25 | : F(f), Condition(condition) {}
26 | virtual ~Functor_conditional() {}
27 | void operator()() const {
28 | bool goOn = true;
29 | for (size_t i = 0; ievaluate()==false) {
31 | goOn = false;
32 | break;
33 | }
34 | }
35 | if (goOn == true) {
36 | F->operator()();
37 | }
38 | }
39 | const Functor* F;
40 | std::vector Condition;
41 | };
42 | }
43 |
44 | using namespace flopc;
45 |
46 | const MP_domain* MP_domain::Empty = NULL;
47 |
48 | const MP_domain& MP_domain::getEmpty() {
49 | if(Empty==NULL) {
50 | Empty= new MP_domain(new MP_domain_set(&MP_set::getEmpty(),&MP_set::getEmpty()));
51 | }
52 | return *Empty;
53 | }
54 |
55 |
56 | MP_domain_base::MP_domain_base() : count(0), donext(0) {}
57 | MP_domain_base::~MP_domain_base() {}
58 |
59 | Functor* MP_domain_base::makeInsertFunctor() const {
60 | return NULL;
61 | }
62 |
63 | size_t MP_domain_base::size() const {
64 | return count;
65 | }
66 |
67 |
68 | void MP_domain_base::display()const {
69 | std::stringstream ss;
70 | ss<<"domain_base::display() size="<getMessenger()->logMessage(5,ss.str().c_str());
72 | }
73 |
74 | MP_domain::MP_domain() : Handle(0), last(0) {}
75 | MP_domain::MP_domain(MP_domain_base* r) : Handle(r), last(r) {}
76 | MP_domain::~MP_domain() {}
77 |
78 | MP_domain MP_domain::such_that(const MP_boolean& b) {
79 | if (b.operator ->() != 0) {
80 | condition.push_back(b);
81 | }
82 | return *this;
83 | }
84 |
85 | void MP_domain::Forall(const Functor* op) const {
86 | if (condition.size()>0) {
87 | last->donext = new Functor_conditional(op,condition);
88 | } else {
89 | last->donext = op;
90 | }
91 | operator->()->operator()();
92 | }
93 |
94 | const MP_set_base* MP_domain_set::getSet() const {
95 | return S;
96 | }
97 |
98 | size_t MP_domain::size() const {
99 | return operator->()->getSet()->size();
100 | }
101 |
102 | int MP_domain_set::evaluate() const {
103 | return I->evaluate();
104 | }
105 |
106 | void MP_domain_set::operator()() const {
107 | if (I->isInstantiated() == true) {
108 | (*donext)();
109 | } else {
110 | I->instantiate();
111 | for (int k=0; ksize(); k++) {
112 | I->assign(k);
113 | (*donext)();
114 | }
115 | I->assign(0);
116 | I->unInstantiate();
117 | }
118 | }
119 |
120 | MP_index* MP_domain_set::getIndex() const {
121 | return I;
122 | }
123 |
124 |
125 | flopc::MP_domain flopc::operator*(const flopc::MP_domain& a, const flopc::MP_domain& b) {
126 | if (a.operator->() == MP_domain::getEmpty().operator->()) {
127 | return b;
128 | } else if (b.operator->() == MP_domain::getEmpty().operator->()) {
129 | return a;
130 | } else {
131 | MP_domain retval = a;
132 | retval.last->donext = b.operator->();
133 | const_cast(b).increment();
134 | const_cast(a).increment();
135 | retval.last = b.last;
136 | retval.condition.insert(retval.condition.end(),b.condition.begin(),
137 | b.condition.end());
138 | return retval;
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/FlopCpp/src/MP_index.cpp:
--------------------------------------------------------------------------------
1 | // ******************** FlopCpp **********************************************
2 | // File: MP_index.cpp
3 | // $Id$
4 | // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 | // Copyright (C) 2003 Tim Helge Hultberg
6 | // All Rights Reserved.
7 | //****************************************************************************
8 |
9 | #include "MP_index.hpp"
10 | #include "MP_domain.hpp"
11 | #include "MP_set.hpp"
12 | #include "MP_model.hpp"
13 |
14 | namespace flopc {
15 | // Initialization of static member data
16 | MP_index& MP_index::Empty = *new MP_index();
17 | MP_index& MP_index::Any = *new MP_index();
18 | MP_index_exp MP_index_exp::Empty = *new MP_index_exp(Constant(0.0));
19 |
20 | MP_index &MP_index::getEmpty() {
21 | return Empty;
22 | }
23 | const MP_index_exp &MP_index_exp::getEmpty() {
24 | return Empty;
25 | }
26 |
27 | void MP_index_base::display()const {
28 | /// MP_model::getCurrentModel()->getMessenger()->logMessage(5,toString().c_str());
29 | }
30 |
31 | class MP_index_constant : public MP_index_base {
32 | friend class MP_index_exp;
33 | public:
34 | void display()const {
35 | /// MP_model::getCurrentModel()->getMessenger()->logMessage(5,toString().c_str());
36 | }
37 | private:
38 | MP_index_constant(const Constant& c) : C(c) {}
39 | int evaluate() const {
40 | return int(C->evaluate());
41 | }
42 | MP_index* getIndex() const {
43 | return 0;
44 | }
45 | virtual MP_domain getDomain(MP_set* s) const{
46 | return MP_domain::getEmpty();
47 | }
48 | Constant C;
49 | };
50 |
51 | class MP_index_subsetRef : public MP_index_base {
52 | friend class MP_index_exp;
53 | public:
54 | void display()const {
55 | /// MP_model::getCurrentModel()->getMessenger()->logMessage(5,toString().c_str());
56 | }
57 | private:
58 | MP_index_subsetRef(const SUBSETREF& s) : S(&s) {}
59 | int evaluate() const {
60 | return int(S->evaluate());
61 | }
62 | MP_index* getIndex() const {
63 | return S->getIndex();
64 | }
65 | virtual MP_domain getDomain(MP_set* s) const{
66 | return MP_domain(S->getDomain(s));
67 | }
68 | const SUBSETREF* S;
69 | };
70 |
71 | MP_index_exp operator+(MP_index& i,const Constant& j) {
72 | return new MP_index_sum(i,j);
73 | }
74 |
75 | MP_index_exp operator+(MP_index& i,const int& j) {
76 | return new MP_index_sum(i,Constant(j));
77 | }
78 |
79 | MP_index_exp operator-(MP_index& i,const Constant& j) {
80 | return new MP_index_dif(i,j);
81 | }
82 |
83 | MP_index_exp operator-(MP_index& i,const int& j) {
84 | return new MP_index_dif(i,Constant(j));
85 | }
86 |
87 | MP_index_exp operator*(MP_index& i,const Constant& j) {
88 | return new MP_index_mult(i,j);
89 | }
90 |
91 |
92 | } // End of namespace flopc
93 |
94 | using namespace flopc;
95 |
96 |
97 | MP_domain MP_index::getDomain(MP_set* s) const{
98 | return new MP_domain_set(s,const_cast(this)) ;
99 | }
100 |
101 | MP_domain MP_index_mult::getDomain(MP_set* s) const{
102 | return left->getDomain(s);
103 | }
104 |
105 | MP_domain MP_index_sum::getDomain(MP_set* s) const{
106 | return left->getDomain(s);
107 | }
108 |
109 | MP_domain MP_index_dif::getDomain(MP_set* s) const{
110 | return left->getDomain(s);
111 | }
112 |
113 | MP_index_exp::MP_index_exp(int i) :
114 | Handle(new MP_index_constant(Constant(i))) {}
115 |
116 | MP_index_exp::MP_index_exp(const SUBSETREF& s) :
117 | Handle(new MP_index_subsetRef(s)) {}
118 |
119 | MP_index_exp::MP_index_exp(const Constant& c) :
120 | Handle(new MP_index_constant(c)) {}
121 |
122 | MP_index_exp::MP_index_exp(MP_index& i) :
123 | Handle(&i) { operator->()->count++; }
124 |
125 | MP_index_exp::MP_index_exp(const MP_index_exp &other):
126 | Handle((const Handle &)other) {}
127 |
128 |
--------------------------------------------------------------------------------
/FlopCpp/src/MP_set.cpp:
--------------------------------------------------------------------------------
1 | // ******************** FlopCpp **********************************************
2 | // File: MP_set.cpp
3 | // $Id$
4 | // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 | // Copyright (C) 2003 Tim Helge Hultberg
6 | // All Rights Reserved.
7 | //****************************************************************************
8 |
9 | #include "MP_set.hpp"
10 | #include "MP_model.hpp"
11 | #include
12 | using namespace flopc;
13 |
14 | namespace flopc {
15 |
16 | MP_set MP_set::Empty = *new MP_set(1);
17 | MP_set &MP_set::getEmpty() {
18 | return Empty;
19 | }
20 |
21 | void MP_set_base::display()const {
22 | //I don't like this hack. However, until messenger is segregated from the
23 | // model, it's pretty impossible to use it in a shared fashion.
24 | /// MP_model::getCurrentModel()->getMessenger()->logMessage(5,toString().c_str());
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/FlopCpp/src/MP_utilities.cpp:
--------------------------------------------------------------------------------
1 | // ******************** FlopCpp **********************************************
2 | // File: MP_utilities.cpp
3 | // $Id$
4 | // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 | // Copyright (C) 2003 Tim Helge Hultberg
6 | // All Rights Reserved.
7 | //****************************************************************************
8 |
9 | #include "MP_utilities.hpp"
10 | using namespace flopc;
11 |
12 |
--------------------------------------------------------------------------------
/FlopCpp/src/MP_utilities.hpp:
--------------------------------------------------------------------------------
1 | // ******************** FlopCpp **********************************************
2 | // File: MP_utilities.hpp
3 | // $Id$
4 | // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 | // Copyright (C) 2003 Tim Helge Hultberg
6 | // All Rights Reserved.
7 | // ****************************************************************************
8 |
9 | #ifndef _MP_utilities_hpp_
10 | #define _MP_utilities_hpp_
11 |
12 | #include
13 | #include
14 |
15 | namespace flopc {
16 |
17 | /** @file This file contains several different useful utilities which are
18 | used to simplify use of FlopC++.
19 | @ingroup PublicInterface
20 | */
21 |
22 | /** @brief Function object. Often used
23 | @ingroup INTERNAL_USE
24 | @note is the base class for passing a fucntion object around.
25 | */
26 | class Functor {
27 | public:
28 | virtual void operator()() const = 0;
29 | protected:
30 | Functor() {}
31 | virtual ~Functor() {}
32 | private:
33 | Functor(const Functor&);
34 | Functor& operator=(const Functor&);
35 | };
36 |
37 | /** This template makes a vector of appropriate size out of the
38 | variable number of arguments.
39 | @ingroup INTERNAL_USE
40 | */
41 | template
42 | std::vector makeVector(T i1, T i2=0, T i3=0, T i4=0, T i5=0) {
43 | std::vector S(nbr);
44 | S[0] = i1;
45 | if (nbr==1) return S;
46 | S[1] = i2;
47 | if (nbr==2) return S;
48 | S[2] = i3;
49 | if (nbr==3) return S;
50 | S[3] = i4;
51 | if (nbr==4) return S;
52 | S[4] = i5;
53 | return S;
54 | }
55 |
56 | /// return the strictly positive modulus of two integers
57 | inline int mod(int a, int b) {
58 | int t = a % b;
59 | return (t>=0) ? t : t+b;
60 | }
61 |
62 | /// Distinct return value on conditions where an index goes out of bounds.
63 | const int outOfBound = -2;
64 |
65 | /** Utility class to flatten multidimensional information into single
66 | dimentional offset information.
67 | @ingroup INTERNAL_USE
68 | */
69 | class RowMajor {
70 | public:
71 | int size() const { return size_; }
72 | protected:
73 | RowMajor(int s1, int s2, int s3, int s4, int s5) :
74 | size1(s1), size2(s2), size3(s3), size4(s4), size5(s5),
75 | size_(s1*s2*s3*s4*s5) {}
76 | int f(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const {
77 | if ( i1==outOfBound || i2==outOfBound || i3==outOfBound ||
78 | i4==outOfBound || i5==outOfBound ) {
79 | return outOfBound;
80 | } else {
81 | int i = i1;
82 | i *= size2; i += i2; i *= size3; i += i3;
83 | i *= size4; i += i4; i *= size5; i += i5;
84 | return i;
85 | }
86 | }
87 | int size1,size2,size3,size4,size5,size_;
88 | };
89 |
90 | /** @brief Utility interface class for adding a string name onto a
91 | structure.
92 | @ingroup INTERNAL_USE
93 | */
94 | class Named {
95 | public:
96 | std::string getName() const { return name; }
97 | void setName(const std::string& n) { name = n; }
98 | private:
99 | std::string name;
100 | };
101 |
102 | /** @brief Utility for doing reference counted pointers.
103 | @ingroup INTERNAL_USE
104 | */
105 | template class Handle {
106 | public:
107 | const T &operator->() const {
108 | return root;
109 | }
110 | Handle(const T &r) : root(r) {
111 | increment();
112 | }
113 | Handle(const Handle& h) : root(h.root) {
114 | increment();
115 | }
116 | const Handle& operator=(const Handle& h) {
117 | if (root != h.root) {
118 | decrement();
119 | root = h.root;
120 | increment();
121 | }
122 | return *this;
123 | }
124 | ~Handle() {
125 | decrement();
126 | }
127 | protected:
128 | void increment() {
129 | if(root != 0) {
130 | (root->count)++;
131 | }
132 | }
133 | void decrement() {
134 | if(root != 0) {
135 | if(root->count == 1) {
136 | delete root;
137 | root = 0;
138 | } else {
139 | ///if(root->count != 0) {
140 | --(root->count);
141 | ///}
142 | }
143 | }
144 | }
145 | private:
146 | Handle() : root(0) {}
147 | T root;
148 | };
149 |
150 | } // End of namespace flopc
151 | #endif
152 |
--------------------------------------------------------------------------------
/FlopCpp/src/MP_variable.cpp:
--------------------------------------------------------------------------------
1 | // ******************** FlopCpp **********************************************
2 | // File: MP_variable.cpp
3 | // $Id$
4 | // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 | // Copyright (C) 2003 Tim Helge Hultberg
6 | // All Rights Reserved.
7 | //****************************************************************************
8 |
9 | #include
10 | #include
11 |
12 | #include
13 | #include "MP_variable.hpp"
14 | #include "MP_domain.hpp"
15 | #include "MP_constant.hpp"
16 | #include "MP_model.hpp"
17 |
18 | using namespace flopc;
19 | using namespace std;
20 |
21 | VariableRef::VariableRef(MP_variable* v,
22 | const MP_index_exp& i1,
23 | const MP_index_exp& i2,
24 | const MP_index_exp& i3,
25 | const MP_index_exp& i4,
26 | const MP_index_exp& i5) :
27 | V(v),I1(i1),I2(i2),I3(i3),I4(i4),I5(i5) {
28 | offset = v->offset;
29 | }
30 |
31 | double VariableRef::level() const {
32 | return V->M->solution[V->offset +
33 | V->f(V->S1->evaluate(),
34 | V->S2->evaluate(),
35 | V->S3->evaluate(),
36 | V->S4->evaluate(),
37 | V->S5->evaluate())];
38 | }
39 |
40 | int VariableRef::getColumn() const {
41 | int i1 = V->S1->check(I1->evaluate());
42 | int i2 = V->S2->check(I2->evaluate());
43 | int i3 = V->S3->check(I3->evaluate());
44 | int i4 = V->S4->check(I4->evaluate());
45 | int i5 = V->S5->check(I5->evaluate());
46 |
47 | if (i1==outOfBound || i2==outOfBound || i3==outOfBound ||
48 | i4==outOfBound || i5==outOfBound) {
49 | return outOfBound;
50 | } else {
51 | return V->offset + V->f(i1,i2,i3,i4,i5);
52 | }
53 | }
54 |
55 | void VariableRef::generate(const MP_domain& domain,
56 | vector multiplicators,
57 | GenerateFunctor& f,
58 | double m) const {
59 | f.setMultiplicator(multiplicators,m);
60 | f.setTerminalExpression(this);
61 | domain.Forall(&f);
62 | }
63 |
64 | MP_variable::MP_variable(const MP_set_base &s1,
65 | const MP_set_base &s2,
66 | const MP_set_base &s3,
67 | const MP_set_base &s4,
68 | const MP_set_base &s5) :
69 | RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
70 | upperLimit(MP_data(s1,s2,s3,s4,s5)),
71 | lowerLimit(MP_data(s1,s2,s3,s4,s5)),
72 | S1(&s1),S2(&s2),S3(&s3),S4(&s4),S5(&s5),
73 | offset(-1)
74 | {
75 | lowerLimit.initialize(0.0);
76 | upperLimit.initialize(MP_model::getDefaultModel().getInfinity());
77 | type = continuous;
78 | }
79 |
80 | double MP_variable::level(int lcl_i1, int lcl_i2, int lcl_i3, int lcl_i4, int lcl_i5) {
81 | return M->solution[offset + f(lcl_i1,lcl_i2,lcl_i3,lcl_i4,lcl_i5)];
82 | }
83 |
84 | void MP_variable::operator()() const {
85 | if (S1!=&MP_set::getEmpty()) cout << i1.evaluate() << " ";
86 | if (S2!=&MP_set::getEmpty()) cout << i2.evaluate() << " ";
87 | if (S3!=&MP_set::getEmpty()) cout << i3.evaluate() << " ";
88 | if (S4!=&MP_set::getEmpty()) cout << i4.evaluate() << " ";
89 | if (S5!=&MP_set::getEmpty()) cout << i5.evaluate() << " ";
90 | cout<<" "<< M->solution[offset +
91 | f(i1.evaluate(),
92 | i2.evaluate(),
93 | i3.evaluate(),
94 | i4.evaluate(),
95 | i5.evaluate())]<= 0) {
101 | ((*S1)(i1)*(*S2)(i2)*(*S3)(i3)*(*S4)(i4)*(*S5)(i5)).Forall(this);
102 | } else {
103 | cout<<"No solution available!"<
13 | #include
14 |
15 | #include "MP_set.hpp"
16 | #include "MP_index.hpp"
17 | #include "MP_expression.hpp"
18 | #include "MP_domain.hpp"
19 | #include "MP_data.hpp"
20 |
21 | namespace flopc {
22 |
23 | /** @brief Enumeration for indicating variable type
24 | @ingroup INTERNAL_USE
25 | */
26 | enum variableType {continuous, discrete};
27 |
28 | class MP_model;
29 | class MP_variable;
30 |
31 | /** Semantic representation of a variable in a Math Program
32 | @ingroup INTERNAL_USE
33 | @see MP_variable for a public interface.
34 | */
35 | class VariableRef : public TerminalExpression {
36 | friend class MP_variable;
37 | public:
38 | int getColumn() const;
39 | private:
40 | VariableRef(MP_variable* v,
41 | const MP_index_exp& i1,
42 | const MP_index_exp& i2,
43 | const MP_index_exp& i3,
44 | const MP_index_exp& i4,
45 | const MP_index_exp& i5);
46 |
47 | double level() const;
48 |
49 | void insertVariables(std::set& v) const {
50 | v.insert(V);
51 | }
52 | double getValue() const {
53 | return 1.0;
54 | }
55 | int getStage() const {
56 | return 0;
57 | }
58 | void generate(const MP_domain& domain,
59 | std::vector multiplicators,
60 | GenerateFunctor& f,
61 | double m) const;
62 | MP_variable* V;
63 | int offset;
64 | const MP_index_exp I1,I2,I3,I4,I5;
65 | };
66 |
67 |
68 | /** @brief Symantic representation of a variable.
69 | @ingroup PublicInterface
70 | This is one of the main public interface classes.
71 | It should be directly declared by clients of the FlopC++. The
72 | parametersof construction are MP_set s which specify the indexes
73 | over which the variable is defined.
74 | */
75 | class MP_variable : public RowMajor, public Functor , public Named{
76 | friend class MP_model;
77 | friend class DisplayVariable;
78 | friend class VariableRef;
79 | public:
80 | MP_variable(const MP_set_base &s1 = MP_set::getEmpty(),
81 | const MP_set_base &s2 = MP_set::getEmpty(),
82 | const MP_set_base &s3 = MP_set::getEmpty(),
83 | const MP_set_base &s4 = MP_set::getEmpty(),
84 | const MP_set_base &s5 = MP_set::getEmpty());
85 |
86 | void display(const std::string &s = "");
87 |
88 | ~MP_variable() {
89 | }
90 |
91 | /// Returns the value of the variable given the specific index values.
92 | double level(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0);
93 |
94 | /// Interal use only.
95 | const VariableRef& operator()(
96 | const MP_index_exp& d1 = MP_index_exp::getEmpty(),
97 | const MP_index_exp& d2 = MP_index_exp::getEmpty(),
98 | const MP_index_exp& d3 = MP_index_exp::getEmpty(),
99 | const MP_index_exp& d4 = MP_index_exp::getEmpty(),
100 | const MP_index_exp& d5 = MP_index_exp::getEmpty()
101 | ) {
102 | return *new VariableRef(this, d1, d2, d3, d4, d5);
103 | }
104 |
105 | //void display(string s = "");
106 |
107 | /// Call this method to turn the variable into a binary variable
108 | void binary() {
109 | upperLimit.initialize(1);
110 | type = discrete;
111 | }
112 |
113 | /// Call this method to turn the MP_variable into an integer variable
114 | void integer() {
115 | type = discrete;
116 | }
117 |
118 | /// Upper bound on the variable value.
119 | MP_data upperLimit;
120 | /// Lower bound on the variable value.
121 | MP_data lowerLimit;
122 | private:
123 | void operator()() const;
124 | const MP_set_base *S1, *S2, *S3, *S4, *S5;
125 | MP_index i1,i2,i3,i4,i5;
126 |
127 | MP_model *M;
128 | variableType type;
129 | int offset;
130 | };
131 |
132 | /** Specialized subclass of MP_variable where the variable is
133 | pre-specified to be binary.
134 | @ingroup PublicInterface
135 | */
136 | class MP_binary_variable : public MP_variable {
137 | public:
138 | MP_binary_variable(const MP_set_base &s1 = MP_set::getEmpty(),
139 | const MP_set_base &s2 = MP_set::getEmpty(),
140 | const MP_set_base &s3 = MP_set::getEmpty(),
141 | const MP_set_base &s4 = MP_set::getEmpty(),
142 | const MP_set_base &s5 = MP_set::getEmpty()) :
143 | MP_variable(s1,s2,s3,s4,s5) {
144 | binary();
145 | }
146 | };
147 |
148 | } // End of namespace flopc
149 | #endif
150 |
--------------------------------------------------------------------------------
/FlopCpp/src/Makefile.am:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2006 International Business Machines and others.
2 | # All Rights Reserved.
3 | # This file is distributed under the Common Public License.
4 |
5 | ## $Id$
6 |
7 | # Author: Andreas Waechter IBM 2006-04-13
8 |
9 | AUTOMAKE_OPTIONS = foreign
10 |
11 | ########################################################################
12 | # libFlopCpp #
13 | ########################################################################
14 |
15 | # Name of the library compiled in this directory. We want it to be installed
16 | # in the 'lib' directory
17 | lib_LTLIBRARIES = libFlopCpp.la
18 |
19 | # List all source files for this library, including headers
20 | libFlopCpp_la_SOURCES = \
21 | flopc.hpp \
22 | FlopCppConfig.h \
23 | MP_boolean.cpp MP_boolean.hpp \
24 | MP_constant.cpp MP_constant.hpp \
25 | MP_constraint.cpp MP_constraint.hpp \
26 | MP_data.cpp MP_data.hpp \
27 | MP_domain.cpp MP_domain.hpp \
28 | MP_expression.cpp MP_expression.hpp \
29 | MP_index.cpp MP_index.hpp \
30 | MP_model.cpp MP_model.hpp \
31 | MP_set.cpp MP_set.hpp \
32 | MP_utilities.cpp MP_utilities.hpp \
33 | MP_variable.cpp MP_variable.hpp
34 |
35 | # List all additionally required libraries
36 | if DEPENDENCY_LINKING
37 | libFlopCpp_la_LIBADD = $(FLOPCPP_LIBS)
38 | endif
39 |
40 | # This is for libtool
41 | libFlopCpp_la_LDFLAGS = $(LT_LDFLAGS)
42 |
43 | ########################################################################
44 | # Additional flags #
45 | ########################################################################
46 |
47 | # Here list all include flags, relative to this "srcdir" directory. This
48 | # "cygpath" stuff is necessary to compile with native compilers on Windows.
49 | # "top_srcdir" refers to the basic directory for the main package that is
50 | # being compiled.
51 | AM_CPPFLAGS = $(FLOPCPP_CFLAGS)
52 |
53 | # This line is necessary to allow VPATH compilation
54 | DEFAULT_INCLUDES = -I. -I`$(CYGPATH_W) $(srcdir)`
55 |
56 | ########################################################################
57 | # Headers that need to be installed #
58 | ########################################################################
59 |
60 | # Here list all the header files that are required by a user of the library,
61 | # and that therefore should be installed in 'include/coin'
62 | includecoindir = $(includedir)/coin
63 |
64 | includecoin_HEADERS = \
65 | flopc.hpp \
66 | MP_boolean.hpp \
67 | MP_constant.hpp \
68 | MP_constraint.hpp \
69 | MP_data.hpp \
70 | MP_domain.hpp \
71 | MP_expression.hpp \
72 | MP_index.hpp \
73 | MP_model.hpp \
74 | MP_set.hpp \
75 | MP_utilities.hpp \
76 | MP_variable.hpp
77 |
78 | install-exec-local:
79 | $(install_sh_DATA) config_flopcpp.h $(DESTDIR)$(includecoindir)/FlopCppConfig.h
80 |
81 | uninstall-local:
82 | rm -f $(DESTDIR)$(includecoindir)/FlopCppConfig.h
83 |
--------------------------------------------------------------------------------
/FlopCpp/src/config.h.in:
--------------------------------------------------------------------------------
1 | /* src/config.h.in. Generated from configure.ac by autoheader. */
2 |
3 | /* Define to the debug sanity check level (0 is no test) */
4 | #undef COIN_FLOPCPP_CHECKLEVEL
5 |
6 | /* Define to the debug verbosity level (0 is no output) */
7 | #undef COIN_FLOPCPP_VERBOSITY
8 |
9 | /* Define to 1 if the Cbc package is available */
10 | #undef COIN_HAS_CBC
11 |
12 | /* Define to 1 if the Clp package is available */
13 | #undef COIN_HAS_CLP
14 |
15 | /* Define to 1 if the Osi package is available */
16 | #undef COIN_HAS_OSI
17 |
18 | /* SVN revision number of project */
19 | #undef FLOPCPP_SVN_REV
20 |
21 | /* Version number of project */
22 | #undef FLOPCPP_VERSION
23 |
24 | /* Major Version number of project */
25 | #undef FLOPCPP_VERSION_MAJOR
26 |
27 | /* Minor Version number of project */
28 | #undef FLOPCPP_VERSION_MINOR
29 |
30 | /* Release Version number of project */
31 | #undef FLOPCPP_VERSION_RELEASE
32 |
33 | /* Define to 1 if you have the header file. */
34 | #undef HAVE_DLFCN_H
35 |
36 | /* Define to 1 if you have the header file. */
37 | #undef HAVE_INTTYPES_H
38 |
39 | /* Define to 1 if you have the header file. */
40 | #undef HAVE_MEMORY_H
41 |
42 | /* Define to 1 if you have the header file. */
43 | #undef HAVE_STDINT_H
44 |
45 | /* Define to 1 if you have the header file. */
46 | #undef HAVE_STDLIB_H
47 |
48 | /* Define to 1 if you have the header file. */
49 | #undef HAVE_STRINGS_H
50 |
51 | /* Define to 1 if you have the header file. */
52 | #undef HAVE_STRING_H
53 |
54 | /* Define to 1 if you have the header file. */
55 | #undef HAVE_SYS_STAT_H
56 |
57 | /* Define to 1 if you have the header file. */
58 | #undef HAVE_SYS_TYPES_H
59 |
60 | /* Define to 1 if you have the header file. */
61 | #undef HAVE_UNISTD_H
62 |
63 | /* Name of package */
64 | #undef PACKAGE
65 |
66 | /* Define to the address where bug reports for this package should be sent. */
67 | #undef PACKAGE_BUGREPORT
68 |
69 | /* Define to the full name of this package. */
70 | #undef PACKAGE_NAME
71 |
72 | /* Define to the full name and version of this package. */
73 | #undef PACKAGE_STRING
74 |
75 | /* Define to the one symbol short name of this package. */
76 | #undef PACKAGE_TARNAME
77 |
78 | /* Define to the version of this package. */
79 | #undef PACKAGE_VERSION
80 |
81 | /* Define to 1 if you have the ANSI C header files. */
82 | #undef STDC_HEADERS
83 |
84 | /* Version number of package */
85 | #undef VERSION
86 |
--------------------------------------------------------------------------------
/FlopCpp/src/config_flopcpp.h.in:
--------------------------------------------------------------------------------
1 | /* src/config_flopcpp.h.in. */
2 |
3 | /* Version number of project */
4 | #undef FLOPCPP_VERSION
5 |
6 | /* Major Version number of project */
7 | #undef FLOPCPP_VERSION_MAJOR
8 |
9 | /* Minor Version number of project */
10 | #undef FLOPCPP_VERSION_MINOR
11 |
12 | /* Release Version number of project */
13 | #undef FLOPCPP_VERSION_RELEASE
14 |
--------------------------------------------------------------------------------
/FlopCpp/src/config_flopcpp_default.h:
--------------------------------------------------------------------------------
1 |
2 | /***************************************************************************/
3 | /* HERE DEFINE THE PROJECT SPECIFIC PUBLIC MACROS */
4 | /* These are only in effect in a setting that doesn't use configure */
5 | /***************************************************************************/
6 |
7 | /* Version number of project */
8 | #define FLOPCPP_VERSION "trunk"
9 |
10 | /* Major Version number of project */
11 | #define FLOPCPP_VERSION_MAJOR 9999
12 |
13 | /* Minor Version number of project */
14 | #define FLOPCPP_VERSION_MINOR 9999
15 |
16 | /* Release Version number of project */
17 | #define FLOPCPP_VERSION_RELEASE 9999
18 |
--------------------------------------------------------------------------------
/FlopCpp/src/flopc.cpp:
--------------------------------------------------------------------------------
1 | // ******************** FlopCpp **********************************************
2 | // File: flopc.cpp
3 | // $Id$
4 | // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 | // Copyright (C) 2003 Tim Helge Hultberg
6 | // All Rights Reserved.
7 | //****************************************************************************
8 |
9 | #include "flopc.hpp"
10 |
11 | namespace flopc {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/FlopCpp/src/flopc.hpp:
--------------------------------------------------------------------------------
1 | // ******************** FlopCpp **********************************************
2 | // File: flopc.hpp
3 | // $Id$
4 | // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 | // Copyright (C) 2003 Tim Helge Hultberg
6 | // All Rights Reserved.
7 | // ****************************************************************************
8 |
9 | #ifndef _flopc_hpp_
10 | #define _flopc_hpp_
11 |
12 | #include "MP_variable.hpp"
13 | #include "MP_set.hpp"
14 | #include "MP_index.hpp"
15 | #include "MP_constant.hpp"
16 | #include "MP_data.hpp"
17 | #include "MP_constraint.hpp"
18 | #include "MP_expression.hpp"
19 | #include "MP_boolean.hpp"
20 | #include "MP_model.hpp"
21 |
22 | /** @defgroup PublicInterface Public interface
23 | @brief Classes in this group are for normal modeling purposes.
24 | They are intended for consumption outside the library.
25 | */
26 | /** @defgroup INTERNAL_USE Internal (private) interface.
27 | @brief Classes in this group are used for internal purposes.
28 | They are not intended for consumption outside the library.
29 | */
30 | /** @brief All flopc++ code is contained within the flopc namespace.
31 |
32 | Flopc++ is an open source algebraic modelling language implemented as
33 | a C++ class library. It uses the common COIN-OR OsiSolverInterface
34 | abstract interface to allow for easy integration with many of today's top
35 | Math Programming solvers.
36 | The main 3 components are listed below. Much of the rest of
37 | the code is to facilitate the operator overloading makes this such
38 | a powerful modeling environment.
39 | @li Linear Variables MP_variable
40 | @li Linear Set MP_set
41 | @li Linear Index MP_index
42 | @li Linear Constraints MP_constraint
43 |
44 |
45 | @note The classes in @group PublicInterface are intended for consumption
46 | outside the library.
47 |
48 | */
49 | namespace flopc {
50 |
51 | /** @brief Global function for performing a Functor on each member of a
52 | MP_domain
53 | @ingroup PublicInterface
54 | */
55 | inline void forall(const MP_domain& d, const Functor& f) {
56 | d.Forall(&f);
57 | }
58 |
59 | /** @brief Global function for performing a Functor without having a set
60 | to operate on.
61 | @ingroup PublicInterface
62 | @todo This turns into a no-op?
63 | */
64 | inline void forall(const Functor& f) {
65 | forall(MP_domain::getEmpty(), f);
66 | }
67 |
68 | /** @brief Global function which copies members of MP_domain d into
69 | another (possibly non-empty) MP_domain
70 | @ingroup PublicInterface
71 | */
72 | inline void operator<<=(const MP_domain& s, const MP_domain& d) {
73 | d.Forall( s->makeInsertFunctor());
74 | }
75 |
76 | /** @brief This is one of the main entry points for execution
77 | @ingroup PublicInterface
78 | This calls the OsiSolverInterface to execute the solver with the
79 | objective of MINIMIZING the argment MP_expression.
80 | @li Assumes that the OsiSolverInterface is already set
81 | @li Assumes a model is already loaded (and is the default model)
82 | */
83 | inline void minimize(const MP_expression &obj) {
84 | MP_model::getDefaultModel().minimize(obj);
85 | }
86 |
87 | /** @brief This is one of the main entry points for execution
88 | @ingroup PublicInterface
89 | This calls the OsiSolverInterface to execute the solver with the
90 | objective of MINIMIZING THE MAXIMUM of the MP_expression evaluation
91 | of the MP_set
92 | @todo true?
93 | @li Assumes that the OsiSolverInterface is already set
94 | @li Assumes a model is already loaded (and is the default model)
95 | */
96 | inline void minimize_max(MP_set& d, const MP_expression &obj) {
97 | MP_model::getDefaultModel().minimize_max(d,obj);
98 | }
99 |
100 | /** @brief This is one of the main entry points for execution
101 | @ingroup PublicInterface
102 | This calls the OsiSolverInterface to execute the solver with the
103 | objective of MAXIMIZING of the MP_expression
104 | @li Assumes that the OsiSolverInterface is already set
105 | @li Assumes a model is already loaded (and is the default model)
106 | */
107 | inline void maximize(const MP_expression &obj) {
108 | MP_model::getDefaultModel().maximize(obj);
109 | }
110 |
111 | } // End of namespace flopc
112 | #endif
113 |
--------------------------------------------------------------------------------
/FlopCpp/test/Makefile.am:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2006 International Business Machines and others.
2 | # All Rights Reserved.
3 | # This file is distributed under the Common Public License.
4 |
5 | ## $Id$
6 |
7 | # Author: Andreas Waechter IBM 2006-04-13
8 |
9 | AUTOMAKE_OPTIONS = foreign
10 |
11 | ########################################################################
12 | # unitTest for FlopCpp #
13 | ########################################################################
14 |
15 | if COIN_HAS_CBC
16 |
17 | noinst_PROGRAMS = unitTest
18 |
19 | unitTest_SOURCES = unitTest.cpp
20 |
21 | # List libraries of COIN-OR projects
22 | unitTest_LDADD = ../src/libFlopCpp.la $(FLOPCPP_LIBS) $(CBC_LIBS)
23 | unitTest_DEPENDENCIES = ../src/libFlopCpp.la $(FLOPCPP_DEPENDENCIES) $(CBC_DEPENDENCIES)
24 |
25 | # Here list all include flags, relative to this "srcdir" directory. This
26 | # "cygpath" stuff is necessary to compile with native compilers on Windows
27 | AM_CPPFLAGS = -I`$(CYGPATH_W) $(srcdir)/../src` $(FLOPCPP_CFLAGS) $(CBC_CFLAGS)
28 |
29 | test: unitTest$(EXEEXT)
30 | ./unitTest$(EXEEXT)
31 |
32 | else
33 |
34 | test:
35 | echo "Need CBC to run test."
36 | endif
37 |
38 | .PHONY: test
39 |
40 | # This line is necessary to allow VPATH compilation
41 | DEFAULT_INCLUDES = -I. -I`$(CYGPATH_W) $(srcdir)`
42 |
43 | ########################################################################
44 | # Cleaning stuff #
45 | ########################################################################
46 |
47 | # Here we list everything that is not generated by the compiler, e.g.,
48 | # output files of a program
49 |
50 | DISTCLEANFILES =
51 |
--------------------------------------------------------------------------------
/FlopCpp/unittest/Makefile.am:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2006 International Business Machines and others.
2 | # All Rights Reserved.
3 | # This file is distributed under the Common Public License.
4 |
5 | ## $Id: Makefile.am 264 2011-08-07 01:26:00Z tkr $
6 |
7 | # Author: Andreas Waechter IBM 2006-04-13
8 |
9 | AUTOMAKE_OPTIONS = foreign
10 |
11 | ########################################################################
12 | # unitTest for FlopCpp #
13 | ########################################################################
14 |
15 | noinst_PROGRAMS = unitTest
16 |
17 | unitTest_SOURCES = booleanTest.cpp constantTest.cpp indexTest.cpp setTest.cpp TestBed.cpp TestItem.cpp unitTest.cpp
18 |
19 | # List libraries of COIN-OR projects
20 | unitTest_LDADD = ../src/libFlopCpp.la $(FLOPCPP_LIBS)
21 | unitTest_DEPENDENCIES = ../src/libFlopCpp.la $(FLOPCPP_DEPENDENCIES)
22 |
23 | # Here list all include flags, relative to this "srcdir" directory. This
24 | # "cygpath" stuff is necessary to compile with native compilers on Windows
25 | AM_CPPFLAGS = -I`$(CYGPATH_W) $(srcdir)/../src` $(FLOPCPP_CFLAGS)
26 |
27 | test: unitTest$(EXEEXT)
28 | ./unitTest$(EXEEXT)
29 |
30 | .PHONY: test
31 |
32 | # This line is necessary to allow VPATH compilation
33 | DEFAULT_INCLUDES = -I. -I`$(CYGPATH_W) $(srcdir)`
34 |
35 | ########################################################################
36 | # Cleaning stuff #
37 | ########################################################################
38 |
39 | # Here we list everything that is not generated by the compiler, e.g.,
40 | # output files of a program
41 |
42 | DISTCLEANFILES =
43 |
--------------------------------------------------------------------------------
/FlopCpp/unittest/TestBed.cpp:
--------------------------------------------------------------------------------
1 | #include "TestBed.hpp"
2 | #include
3 |
4 | std::ostream &operator<<(std::ostream &os, const TestBed &testBed) {
5 | int passed=0,failed=0;
6 | os<<"TestBed Detail:\n--------------\n";
7 | for(TestBed::const_iterator itemIt = testBed.begin();
8 | itemIt != testBed.end(); itemIt++) {
9 | os<<*(*itemIt)<<'\n';
10 | if((*itemIt)->passed())
11 | passed++;
12 | else
13 | failed++;
14 | }
15 | os<<"\nSummary:\n-----------\n"<
5 | #include
6 |
7 | #include "TestItem.hpp"
8 |
9 | template
10 | struct PLess : std::binary_function {
11 | bool operator()(const T& x, const T& y) const { return *x < *y; }
12 | };
13 |
14 | class TestBed : public std::set < TestItem * , PLess< TestItem * > > {
15 | public:
16 | TestBed(){ std::cout<<"Test begin"<
5 | #include
6 |
7 | TestBed *TestItem::theBed=NULL;
8 |
9 | TestItem::TestItem(const char *itemName)
10 | :name(NULL),success(false),fileName(NULL)
11 | {
12 | name = new char[strlen(itemName)+1];
13 | strcpy(name,itemName);
14 | isSet=false;
15 | if(theBed)
16 | theBed->insert(this);
17 | else
18 | {
19 | std::cerr<<"ERROR: TestItem Static TestBed Not initialized.."<erase( theBed->find(this));
29 | }
30 |
31 | std::ostream &operator<<(std::ostream &os, const TestItem &item) {
32 | if(item.success)
33 | os<<"Passed!";
34 | else
35 | os<<"Failed!";
36 | os<<':'<(const TestItem &item1, const TestItem &item2)
54 | { return (item1.compare(item2)>0); }
55 |
56 | bool operator<=(const TestItem &item1, const TestItem &item2)
57 | { return (item1.compare(item2)<=0); }
58 |
59 | bool operator>=(const TestItem &item1, const TestItem &item2)
60 | { return (item1.compare(item2)>=0); }
61 |
62 | bool operator==(const TestItem &item1, const TestItem &item2)
63 | { return (item1.compare(item2)==0); }
64 |
65 | bool operator!=(const TestItem &item1, const TestItem &item2)
66 | { return (item1.compare(item2)!=0); }
67 |
68 | void TestItem::failItem(const char *_fileName,
69 | const int lineNum)
70 | {
71 | if((!isSet)||(isSet&&success))
72 | {
73 | success=false;
74 | isSet=true;
75 | fileName = new char[strlen(_fileName)+1];
76 | strcpy(fileName,_fileName);
77 | lineNumber = lineNum;
78 | }
79 | }
80 |
81 | void TestItem::expectTrue(const char *_fileName, const int lineNum,
82 | const bool val)
83 | {
84 | if(val)
85 | passItem();
86 | else
87 | {
88 | std::cout<<"FAIL:"<
5 | #include
6 | #include
7 |
8 | class TestBed;
9 |
10 | #define __SPOT__ __FILE__,__LINE__
11 |
12 | class TestItem {
13 | static TestBed *theBed;
14 | char *name;
15 | bool success;
16 | bool isSet;
17 | char *fileName;
18 | int lineNumber;
19 | int compare(const TestItem &otherItem)const;
20 | public:
21 | static void setBed(TestBed *aBed){theBed=aBed;}
22 | TestItem(const char *itemName);
23 | ~TestItem();
24 |
25 | void passItem(){if(!isSet) success=true;isSet=true;}
26 |
27 | void failItem(const char *_fileName,
28 | const int lineNum);
29 |
30 | void expectNonZero(const char *_fileName,
31 | const int lineNum,
32 | const int val);
33 |
34 | void expectFalse(const char *_fileName,
35 | const int lineNum,
36 | const bool val);
37 |
38 | void expectTrue(const char *_fileName,
39 | const int lineNum,
40 | const bool val);
41 |
42 | void expectZero(const char *_fileName,
43 | const int lineNum,
44 | const int val);
45 |
46 | void sameString(const char *fileName, const int lineNum,
47 | const char *string1,const char *string2);
48 |
49 | bool passed(){ return success; }
50 |
51 | friend std::ostream &operator<<(std::ostream &os, const TestItem &item);
52 |
53 | friend bool operator<(const TestItem &item1, const TestItem &item2);
54 | friend bool operator>(const TestItem &item1, const TestItem &item2);
55 | friend bool operator<=(const TestItem &item1, const TestItem &item2);
56 | friend bool operator>=(const TestItem &item1, const TestItem &item2);
57 | friend bool operator==(const TestItem &item1, const TestItem &item2);
58 | friend bool operator!=(const TestItem &item1, const TestItem &item2);
59 | };
60 | #endif
61 |
--------------------------------------------------------------------------------
/FlopCpp/unittest/booleanTest.cpp:
--------------------------------------------------------------------------------
1 | #include "TestItem.hpp"
2 | #include "MP_index.hpp"
3 | #include "MP_set.hpp"
4 | #include "MP_boolean.hpp"
5 | #include "MP_constant.hpp"
6 |
7 | bool booleanTest()
8 | {
9 | TestItem *ti = new TestItem("flopc:booleanTest");
10 |
11 | flopc::MP_set mySet(3);
12 | flopc::MP_index i;
13 | // test alltrue. It's always true. even if the expression is not.
14 | if(alltrue(mySet(i), i>(-1))->evaluate()!=true)
15 | {ti->failItem(__SPOT__);return false;}
16 | if(alltrue(mySet(i), i>(0))->evaluate()!=true)
17 | {ti->failItem(__SPOT__);return false;}
18 |
19 | // test simple construction from a constant and operator&&
20 | flopc::MP_boolean b1(flopc::Constant(3)<=flopc::Constant(4));
21 | flopc::MP_boolean b2(flopc::Constant(4)>=flopc::Constant(3));
22 | if((b1&&b2)->evaluate()!=true)
23 | {ti->failItem(__SPOT__);return false;}
24 |
25 | // test simple construction from a constant and operator||
26 | flopc::MP_boolean b11(flopc::Constant(3)<=flopc::Constant(4));
27 | flopc::MP_boolean b12(flopc::Constant(4)<=flopc::Constant(3));
28 | if((b11||b12)->evaluate()!=true)
29 | {ti->failItem(__SPOT__);return false;}
30 |
31 | // test operator<
32 | flopc::MP_boolean b3(flopc::Constant(3)evaluate()==true)
34 | {ti->failItem(__SPOT__);return false;}
35 |
36 | flopc::MP_boolean b4(flopc::Constant(2)evaluate()!=true)
38 | {ti->failItem(__SPOT__);return false;}
39 |
40 | // test operator>
41 | flopc::MP_boolean b5(flopc::Constant(3)>flopc::Constant(3));
42 | if(b5->evaluate()==true)
43 | {ti->failItem(__SPOT__);return false;}
44 |
45 | flopc::MP_boolean b6(flopc::Constant(3)>flopc::Constant(2));
46 | if(b6->evaluate()!=true)
47 | {ti->failItem(__SPOT__);return false;}
48 |
49 | // test operator==
50 | flopc::MP_boolean b7(flopc::Constant(3)==flopc::Constant(3));
51 | if(b7->evaluate()!=true)
52 | {ti->failItem(__SPOT__);return false;}
53 |
54 | flopc::MP_boolean b8(flopc::Constant(3)==flopc::Constant(2));
55 | if(b8->evaluate()==true)
56 | {ti->failItem(__SPOT__);return false;}
57 |
58 | // test operator!=
59 | flopc::MP_boolean b9(flopc::Constant(3)!=flopc::Constant(3));
60 | if(b9->evaluate()==true)
61 | {ti->failItem(__SPOT__);return false;}
62 |
63 | flopc::MP_boolean b10(flopc::Constant(3)!=flopc::Constant(2));
64 | if(b10->evaluate()!=true)
65 | {ti->failItem(__SPOT__);return false;}
66 |
67 | // test direct construction
68 | if(flopc::MP_boolean(true)->evaluate()!=true)
69 | {ti->failItem(__SPOT__);return false;}
70 | if(flopc::MP_boolean(false)->evaluate()!=false)
71 | {ti->failItem(__SPOT__);return false;}
72 |
73 | // test construction from a Constant .
74 | flopc::MP_boolean b14(flopc::Constant(3));
75 | if(b14->evaluate()!=true)
76 | {ti->failItem(__SPOT__);return false;}
77 |
78 | if(flopc::MP_boolean(flopc::Constant(0))->evaluate()!=false)
79 | {ti->failItem(__SPOT__);return false;}
80 |
81 |
82 |
83 | /** @TODO finish out these tests.
84 | MP_boolean operator<=(const MP_index_exp& e1, const MP_index_exp& e2) {
85 | return new Boolean_lessEq(e1, e2);
86 | }
87 | MP_boolean operator<(const MP_index_exp& e1, const MP_index_exp& e2) {
88 | return new Boolean_less(e1, e2);
89 | }
90 | MP_boolean operator>=(const MP_index_exp& e1, const MP_index_exp& e2) {
91 | return new Boolean_greaterEq(e1, e2);
92 | }
93 | MP_boolean operator>(const MP_index_exp& e1, const MP_index_exp& e2) {
94 | return new Boolean_greater(e1, e2);
95 | }
96 | MP_boolean operator==(const MP_index_exp& e1, const MP_index_exp& e2) {
97 | return new Boolean_equal(e1, e2);
98 | }
99 | MP_boolean operator!=(const MP_index_exp& e1, const MP_index_exp& e2) {
100 | return new Boolean_not_equal(e1, e2);
101 | }
102 |
103 | MP_boolean::MP_boolean(SUBSETREF& c) :
104 | Handle(new Boolean_SUBSETREF(c)) {}
105 |
106 | */
107 | ti->passItem();
108 | return true;
109 | }
110 |
--------------------------------------------------------------------------------
/FlopCpp/unittest/constantTest.cpp:
--------------------------------------------------------------------------------
1 | #include "unitTest.hpp"
2 | #include "MP_constant.hpp"
3 | #include "MP_index.hpp"
4 | #include "MP_set.hpp"
5 | #include "MP_data.hpp"
6 | #include "TestItem.hpp"
7 | #include
8 |
9 | bool constantTest() {
10 | TestItem *ti = new TestItem("flopc:constantTest");
11 | // test absolute value.
12 | if(flopc::abs(-3)->evaluate()!=3.0)
13 | {ti->failItem(__SPOT__); return false;}
14 | if(flopc::abs(3)->evaluate()!=3.0)
15 | {ti->failItem(__SPOT__); return false;}
16 |
17 | // test positive values (or zero)
18 | if(flopc::pos(3)->evaluate()!=3.0)
19 | {ti->failItem(__SPOT__); return false;}
20 |
21 | // test ceil
22 | if(flopc::ceil(2.9)->evaluate()!=3.0)
23 | {ti->failItem(__SPOT__); return false;}
24 |
25 | if(flopc::ceil(3.1)->evaluate()!=4.0)
26 | {ti->failItem(__SPOT__); return false;}
27 |
28 | // test floor
29 | if(flopc::floor(2.9)->evaluate()!=2.0)
30 | {ti->failItem(__SPOT__); return false;}
31 |
32 | if(flopc::floor(3.1)->evaluate()!=3.0)
33 | {ti->failItem(__SPOT__); return false;}
34 |
35 | // test minimum
36 | if(flopc::minimum(flopc::ceil(3.1),flopc::floor(5.1))->evaluate()!=4.0)
37 | {ti->failItem(__SPOT__); return false;}
38 |
39 | if(flopc::minimum(flopc::floor(5.1),flopc::ceil(3.1))->evaluate()!=4.0)
40 | {ti->failItem(__SPOT__); return false;}
41 |
42 | // test maximum
43 | if(flopc::maximum(flopc::ceil(3.1),flopc::floor(5.1))->evaluate()!=5.0)
44 | {ti->failItem(__SPOT__); return false;}
45 |
46 | if(flopc::maximum(flopc::floor(5.1),flopc::ceil(3.1))->evaluate()!=5.0)
47 | {ti->failItem(__SPOT__); return false;}
48 |
49 | // operator+
50 | if((flopc::floor(3.3)+flopc::Constant(3))->evaluate()!=6.0)
51 | {ti->failItem(__SPOT__); return false;}
52 |
53 | // operator- (with constants)
54 | if((flopc::floor(4.3)-flopc::Constant(3))->evaluate()!=1.0)
55 | {ti->failItem(__SPOT__); return false;}
56 |
57 | // operator- (with index values)
58 | flopc::MP_index i;
59 | flopc::MP_index j;
60 | std::cout<<"This isn't really sufficient testing against zero..but it's what I can do."<evaluate()!=0.0)
62 | {ti->failItem(__SPOT__); return false;}
63 |
64 | // operator* (with constants)
65 | if((flopc::floor(4.3)*flopc::Constant(3))->evaluate()!=12.0)
66 | {ti->failItem(__SPOT__); return false;}
67 |
68 | // operator/ (with constants)
69 | if((flopc::floor(4.3)/flopc::Constant(3))->evaluate()!=4.0/3.0)
70 | {ti->failItem(__SPOT__); return false;}
71 |
72 | // maximum over a set. In this case, the set is {0,1,2}, so i+1 = {1,2,3}, so the max is 3.
73 | // also testing construction of a constant from an index expression.
74 | flopc::MP_set mySet(3);
75 | if((flopc::maximum(mySet(i),flopc::abs(i+1)))->evaluate()!=3.0)
76 | {ti->failItem(__SPOT__); return false;}
77 |
78 | // minimum over a set. In this case, the set is {0,1,2}, so i+1 = {1,2,3}, so the min is 1.
79 | // also testing construction of a constant from an index expression.
80 | if((flopc::minimum(mySet(i),flopc::abs(i+1)))->evaluate()!=1.0)
81 | {ti->failItem(__SPOT__); return false;}
82 |
83 | // sum over a set. In this case, the set is {0,1,2}, so i+1 = {1,2,3}, so the sum is 6.
84 | // also testing construction of a constant from an index expression.
85 | if((flopc::sum(mySet(i),flopc::abs(i+1)))->evaluate()!=6.0)
86 | {ti->failItem(__SPOT__); return false;}
87 |
88 | // product over a set. In this case, the set is {0,1,2}, so i+1 = {1,2,3}, so the product is 6.
89 | // also testing construction of a constant from an index expression.
90 | if((flopc::product(mySet(i),flopc::abs(i+1)))->evaluate()!=6.0)
91 | {ti->failItem(__SPOT__); return false;}
92 |
93 | // test construction using a DataRef;
94 | flopc::MP_data myData(mySet);
95 | double d[] = { 1.0,2.0,3.0};
96 | myData.value(d);
97 | if(flopc::abs(myData(1))->evaluate()!=2.0)
98 | {ti->failItem(__SPOT__); return false;}
99 |
100 | ti->passItem();
101 | return true;
102 | }
103 |
--------------------------------------------------------------------------------
/FlopCpp/unittest/indexTest.cpp:
--------------------------------------------------------------------------------
1 | #include "MP_index.hpp"
2 | #include
3 | #include "MP_domain.hpp"
4 | #include "MP_set.hpp"
5 | #include "TestItem.hpp"
6 |
7 | using namespace flopc;
8 | bool indexTest() {
9 | TestItem *ti = new TestItem("flopc:indexTest");
10 | MP_index idx;
11 | if(idx.isInstantiated())
12 | {ti->failItem(__SPOT__); return false;}
13 | idx.instantiate();
14 | if(!idx.isInstantiated())
15 | {ti->failItem(__SPOT__); return false;}
16 | idx.unInstantiate();
17 | if(idx.isInstantiated())
18 | {ti->failItem(__SPOT__); return false;}
19 | idx.assign(3);
20 | if(idx.evaluate()!=3)
21 | {ti->failItem(__SPOT__); return false;}
22 |
23 | MP_index *pIdx = idx.getIndex();
24 | if(pIdx!=&idx)
25 | { ti->failItem(__SPOT__); return false;}
26 |
27 | MP_index &any=MP_index::Any;
28 | MP_index &any2=MP_index::Any;
29 | if(&any!=&any2)
30 | {ti->failItem(__SPOT__); return false; }
31 |
32 | MP_index &empty=MP_index::getEmpty();
33 | MP_index &empty2=MP_index::getEmpty();
34 | if(&empty!=&empty2)
35 | { ti->failItem(__SPOT__); return false; }
36 |
37 | // test constant construction through add/subtr indices.
38 | Constant constant1 = idx+5;
39 | std::cout<<"How tell if this is successful?"<failItem(__SPOT__); return false;}
47 |
48 | std::cout<<"Is there a way to test the correctness of an MP_index_exp directly?"<passItem();
69 | return true;
70 | }
71 |
--------------------------------------------------------------------------------
/FlopCpp/unittest/setTest.cpp:
--------------------------------------------------------------------------------
1 | #include "MP_set.hpp"
2 | #include "TestItem.hpp"
3 |
4 | using namespace flopc;
5 |
6 | class MyBooleanTest: public MP_boolean {
7 | public:
8 | MyBooleanTest(MP_set &s)
9 | :setRef(s) { }
10 | virtual bool evaluate() const {
11 | return setRef.size()==2;
12 | }
13 | private:
14 | MP_set &setRef;
15 | };
16 |
17 | bool setTest() {
18 | TestItem *ti = new TestItem("flopc:setTest");
19 | // test construction.
20 | MP_set set1;
21 | MP_set set2(2);
22 | MP_set set3(3);
23 | if(set1.size()!=0)
24 | {ti->failItem(__SPOT__); return false; }
25 | if(set2.size()!=2)
26 | {ti->failItem(__SPOT__); return false; }
27 |
28 | // conversion to a domain
29 | MP_domain d = set1;
30 | if(d.size()!=0)
31 | {ti->failItem(__SPOT__); return false; }
32 | // convert to a domain but only a particular index setting.
33 | MP_domain d2 = set2(2);
34 | if(d2.size()!=1)
35 | {ti->failItem(__SPOT__); return false; }
36 | MP_index i;
37 | // convert to a domain with a "such_that" clause.
38 | MP_domain d3 = set2.such_that(i<=3);
39 | if(d3.size()!=2) {
40 | ti->failItem(__SPOT__);
41 | return false;
42 | }
43 |
44 | MP_set setCyclic(7); // kinda like week days.
45 | if(setCyclic.size()!=7)
46 | {ti->failItem(__SPOT__); return false; }
47 | enum { A,B,C,ABCSIZE } ;
48 |
49 | MP_set setFromEnum(ABCSIZE);
50 | if(setFromEnum.size()!=3)
51 | {ti->failItem(__SPOT__); return false; }
52 | ti->passItem();
53 | return true;
54 | }
55 |
--------------------------------------------------------------------------------
/FlopCpp/unittest/unitTest.cpp:
--------------------------------------------------------------------------------
1 | #include "unitTest.hpp"
2 | #include
3 |
4 | #include "TestBed.hpp"
5 | #include "TestItem.hpp"
6 |
7 | int main() {
8 | {
9 | TestBed mainBed;
10 | TestItem::setBed(&mainBed);
11 |
12 | bool bSuccess=true;
13 | bSuccess = indexTest();
14 | bSuccess = bSuccess && setTest();
15 | bSuccess = bSuccess && constantTest();
16 | bSuccess = bSuccess && booleanTest();
17 |
18 | /* alternative if you don't like the TestItem TestBed arrangement.
19 | if(bSuccess)
20 | std::cout<<"PASSED"<