Generated on Thu Nov 2 14:49:34 2006 for Gecode/J by doxygen 1.5.0

Steiner.java

Go to the documentation of this file.
00001 /* -*- indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Mikael Lagerkvist, 2006
00009  *     Guido Tack, 2006
00010  *
00011  *  Last modified:
00012  *     $Date: 2006-10-31 16:52:38 +0100 (Tue, 31 Oct 2006) $ by $Author: zayenz $
00013  *     $Revision: 3843 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  See the file "LICENSE" for information on usage and
00020  *  redistribution of this file, and for a
00021  *     DISCLAIMER OF ALL WARRANTIES.
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         /* First alternative:
00073          * Using "the" and sequence constraints
00074          * Gives best propagation
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         /* Breaking symmetries */
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 }