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 package examples;
00026
00027 import static org.gecode.Gecode.*;
00028 import static org.gecode.GecodeEnumConstants.*;
00029
00030 import org.gecode.*;
00031
00038 public class Steiner extends Space {
00039
00040 public VarArray<SetVar> root;
00041
00042 static int n = 9;
00043 static int n1 = n+1;
00044 static int n1n1 = n1*n1;
00045 static int len = (n*(n-1)) / 6;
00046
00047 public Steiner() {
00048 super();
00049
00050 root = new VarArray<SetVar>(this, len, SetVar.class);
00051 for (int i=0; i<len; i++) {
00052 dom(this, root.get(i), SRT_SUB, 1,n);
00053 cardinality(this, root.get(i), 3,3);
00054 }
00055
00056 for (int i=0; i<len; i++) {
00057 for (int j=i+1; j<len; j++) {
00058 SetVar s = new SetVar(this);
00059 SetVar x = root.get(i);
00060 SetVar y = root.get(j);
00061
00062 cardinality(this, s,0,1);
00063 rel(this, x, SOT_INTER, y, SRT_EQ, s);
00064
00065 IntVar x1 = new IntVar(this, 1, n);
00066 IntVar x2 = new IntVar(this, 1, n);
00067 IntVar x3 = new IntVar(this, 1, n);
00068 IntVar y1 = new IntVar(this, 1, n);
00069 IntVar y2 = new IntVar(this, 1, n);
00070 IntVar y3 = new IntVar(this, 1, n);
00071
00072
00073
00074
00075
00076 {
00077 SetVar temp20 = new SetVar(this);
00078 SetVar temp21 = new SetVar(this);
00079 SetVar temp22 = new SetVar(this);
00080 SetVar temp23 = new SetVar(this);
00081 SetVar temp24 = new SetVar(this);
00082 SetVar temp25 = new SetVar(this);
00083 rel(this, temp20, SRT_EQ, x1);
00084 rel(this, temp21, SRT_EQ, x2);
00085 rel(this, temp22, SRT_EQ, x3);
00086 rel(this, temp23, SRT_EQ, y1);
00087 rel(this, temp24, SRT_EQ, y2);
00088 rel(this, temp25, SRT_EQ, y3);
00089 VarArray<SetVar> xargs = new VarArray<SetVar>(temp20, temp21, temp22);
00090 VarArray<SetVar> yargs = new VarArray<SetVar>(temp23, temp24, temp25);
00091
00092 sequentialUnion(this, xargs, x);
00093 sequentialUnion(this, yargs, y);
00094 }
00095
00096
00097
00098 rel(this, x1,IRT_LE,x2,ICL_DEF);
00099 rel(this, x2,IRT_LE,x3,ICL_DEF);
00100 rel(this, x1,IRT_LE,x3,ICL_DEF);
00101
00102 rel(this, y1,IRT_LE,y2,ICL_DEF);
00103 rel(this, y2,IRT_LE,y3,ICL_DEF);
00104 rel(this, y1,IRT_LE,y3,ICL_DEF);
00105
00106 int ia[] = {n1n1,n1,1,-n1n1,-n1,-1};
00107 VarArray<IntVar> iva =
00108 new VarArray<IntVar>(x1, x2, x3, y1, y2, y3);
00109
00110 linear(this, ia, iva, IRT_LE, 0, ICL_DEF);
00111 }
00112 }
00113
00114 branch(this, root, SETBVAR_NONE, SETBVAL_MIN);
00115 }
00116
00117 public Steiner(Boolean share, Steiner steiner) {
00118 super(share, steiner);
00119 root = new VarArray<SetVar>(this, share, steiner.root);
00120 }
00121
00122 public static void main(String[] args) {
00123 Options opt = new Options("Steiner");
00124 opt.size = 0;
00125 opt.gui = false;
00126 opt.solutions = 1;
00127 opt.parse(args);
00128
00129 Steiner steiner = new Steiner();
00130
00131 opt.doSearch(steiner);
00132 }
00133 }