00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <gecode/driver.hh>
00039 #include <gecode/int.hh>
00040 #include <gecode/minimodel.hh>
00041
00042 using namespace Gecode;
00043
00045 const int n_warehouses = 5;
00047 const int n_stores = 10;
00048
00050 const int c_fixed = 30;
00051
00053 const int capacity[n_warehouses] = {
00054 1, 4, 2, 1, 3
00055 };
00056
00058 const int c_supply[n_stores][n_warehouses] = {
00059 {20, 24, 11, 25, 30},
00060 {28, 27, 82, 83, 74},
00061 {74, 97, 71, 96, 70},
00062 { 2, 55, 73, 69, 61},
00063 {46, 96, 59, 83, 4},
00064 {42, 22, 29, 67, 59},
00065 { 1, 5, 73, 59, 56},
00066 {10, 73, 13, 43, 96},
00067 {93, 35, 63, 85, 46},
00068 {47, 65, 55, 71, 95}
00069 };
00070
00071
00072
00099 class Warehouses : public MinimizeScript {
00100 protected:
00102 IntVarArray supplier;
00104 BoolVarArray open;
00106 IntVarArray c_store;
00108 IntVar c_total;
00109 public:
00111 Warehouses(const Options&)
00112 : supplier(*this, n_stores, 0, n_warehouses-1),
00113 open(*this, n_warehouses, 0, 1),
00114 c_store(*this, n_stores) {
00115
00116
00117 for (int s=0; s<n_stores; s++)
00118 element(*this, open, supplier[s], 1);
00119
00120
00121 for (int s=0; s<n_stores; s++) {
00122 IntArgs c(n_warehouses, c_supply[s]);
00123 c_store[s] = expr(*this, element(c, supplier[s]));
00124 }
00125
00126
00127 {
00128 IntSetArgs c(n_warehouses);
00129 for (int w=0; w<n_warehouses; w++)
00130 c[w] = IntSet(0,capacity[w]);
00131 count(*this, supplier, c, ICL_DOM);
00132 }
00133
00134
00135 c_total = expr(*this, c_fixed*sum(open) + sum(c_store));
00136
00137
00138 branch(*this, c_store, INT_VAR_REGRET_MIN_MAX, INT_VAL_MIN);
00139
00140
00141 branch(*this, supplier, INT_VAR_NONE, INT_VAL_MIN);
00142 }
00144 virtual IntVar cost(void) const {
00145 return c_total;
00146 }
00148 Warehouses(bool share, Warehouses& s) : MinimizeScript(share,s) {
00149 supplier.update(*this, share, s.supplier);
00150 open.update(*this, share, s.open);
00151 c_store.update(*this, share, s.c_store);
00152 c_total.update(*this, share, s.c_total);
00153 }
00154
00156 virtual Space*
00157 copy(bool share) {
00158 return new Warehouses(share,*this);
00159 }
00161 virtual void
00162 print(std::ostream& os) const {
00163 os << "\tSupplier: " << supplier << std::endl
00164 << "\tOpen warehouses: " << open << std::endl
00165 << "\tStore cost: " << c_store << std::endl
00166 << "\tTotal cost: " << c_total << std::endl
00167 << std::endl;
00168 }
00169 };
00170
00174 int
00175 main(int argc, char* argv[]) {
00176 Options opt("Warehouses");
00177 opt.solutions(0);
00178 opt.iterations(10);
00179 opt.parse(argc,argv);
00180 MinimizeScript::run<Warehouses,BAB,Options>(opt);
00181 return 0;
00182 }
00183
00184
00185