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 "examples/support.hh"
00039 #include "gecode/minimodel.hh"
00040
00047
00048 class Graph {
00049 public:
00050 const int n_v;
00051 const int n_e;
00052 const int* e;
00053 Graph(const int n_v0, const int n_e0, const int* e0)
00054 : n_v(n_v0), n_e(n_e0), e(e0) {}
00055 };
00056
00057 const int e_20_10[] = {
00058 0, 4, 2,12, 12,14, 18,19, 7,10,
00059 9,12, 5,11, 6,15, 3,18, 7,16
00060 };
00061
00062 const Graph g_20_10(20,10,e_20_10);
00063
00064 const int e_40_20[] = {
00065 21,30, 11,30, 19,38, 20,25, 11,24,
00066 20,33, 8,39, 4, 5, 6,16, 5,32,
00067 0, 9, 5,24, 25,28, 36,38, 14,20,
00068 19,25, 11,22, 13,30, 7,36, 15,33
00069 };
00070
00071 const Graph g_40_20(40, 20, e_40_20);
00073
00074
00081 class IndSet : public Example {
00082 protected:
00084 const Graph& g;
00086 BoolVarArray v;
00088 IntVar k;
00089 public:
00091 IndSet(const SizeOptions& opt)
00092 : g(opt.size() == 0 ? g_20_10 : g_40_20),
00093 v(this,g.n_v,0,1), k(this,0,g.n_e) {
00094 const int* e = g.e;
00095 const int* e1 = e++; const int* e2 = e++;
00096 for (int i = g.n_e; i--; )
00097 rel(this, v[*e1], BOT_AND, v[*e2], 0, ICL_DEF, opt.pk());
00098 linear(this, v, IRT_EQ, k, ICL_DEF, opt.pk());
00099 branch(this, v, INT_VAR_NONE, INT_VAL_MIN);
00100 }
00101
00103 IndSet(bool share, IndSet& s) : Example(share,s), g(s.g) {
00104 v.update(this, share, s.v);
00105 k.update(this, share, s.k);
00106 }
00108 virtual Space*
00109 copy(bool share) {
00110 return new IndSet(share,*this);
00111 }
00112
00114 virtual void
00115 print(std::ostream& os) {
00116 os << "\tk = " << k << std::endl
00117 << "\tv[] = " << v << std::endl;
00118 }
00119
00121 void
00122 constrain(Space* s) {
00123 rel(this, k, IRT_GR, static_cast<IndSet*>(s)->k.val());
00124 }
00125 };
00126
00127
00131 int
00132 main(int argc, char* argv[]) {
00133 SizeOptions opt("IndSet");
00134 opt.solutions(0);
00135 opt.size(1);
00136 opt.iterations(2000);
00137 opt.parse(argc,argv);
00138 Example::run<IndSet,BAB,SizeOptions>(opt);
00139 return 0;
00140 }
00141
00142
00143