Example #1
0
 void
 element(Home home, const SetVarArgs& a,
         IntVar x, int w, IntVar y, int h, SetVar z) {
   if (a.size() == 0)
     throw Set::TooFewArguments("Set::element");
   if (a.size() != w*h)
     throw Set::ArgumentSizeMismatch("Set::element");
   GECODE_POST;
   element(home, a, pair(home,x,w,y,h), z);
 }
Example #2
0
 void
 channel(Home home, const IntVarArgs& x, const SetVarArgs& y) {
   if (home.failed()) return;
   ViewArray<Int::CachedView<Int::IntView> > xa(home,x.size());
   for (int i=x.size(); i--;)
     new (&xa[i]) Int::CachedView<Int::IntView>(x[i]);
   ViewArray<Set::CachedView<Set::SetView> > ya(home,y.size());
   for (int i=y.size(); i--;)
     new (&ya[i]) Set::CachedView<Set::SetView>(y[i]);
   GECODE_ES_FAIL((Set::Int::ChannelInt<Set::SetView>::post(home,xa,ya)));
 }
Example #3
0
  BrancherHandle
  branch(Home home, const SetVarArgs& x,
         SetVarBranch vars, SetValBranch vals,
         const Symmetries& syms,
         SetBranchFilter bf, SetVarValPrint vvp) {
    using namespace Set;
    if (home.failed()) return BrancherHandle();
    vars.expand(home,x);
    ViewArray<SetView> xv(home,x);
    ViewSel<SetView>* vs[1] = { 
      Branch::viewsel(home,vars) 
    };

    // Construct mapping from each variable in the array to its index
    // in the array.
    VariableMap variableMap;
    for (int i = 0 ; i < x.size() ; i++)
      variableMap[x[i].varimp()] = i;
    
    // Convert the modelling-level Symmetries object into an array of
    // SymmetryImp objects.
    int n = syms.size();
    SymmetryImp<SetView>** array = 
      static_cast<Space&>(home).alloc<SymmetryImp<SetView>* >(n);
    for (int i = 0 ; i < n ; i++) {
      array[i] = createSetSym(home, syms[i], variableMap);
    }

    return LDSBSetBrancher<SetView,1,int,2>::post
      (home,xv,vs,Branch::valselcommit(home,vals),array,n,bf,vvp);
  }
Example #4
0
 void
 sequence(Home home, const SetVarArgs& xa) {
   if (xa.size()==0)
     throw TooFewArguments("Set::seq");
   if (home.failed()) return;
   ViewArray<SetView> x(home,xa);
   GECODE_ES_FAIL(Sequence::Seq::post(home, x));
 }
Example #5
0
 void
 atmostOne(Home home, const SetVarArgs& xa, unsigned int c) {
   Set::Limits::check(c, "Set::atmostOne");
   if (home.failed()) return;
   if (xa.size() < 2)
     return;
   ViewArray<SetView> x(home,xa);
   GECODE_ES_FAIL(Distinct::AtmostOne::post(home, x, c));
 }
Example #6
0
  void
  element(Home home, const SetVarArgs& x, IntVar y, SetVar z) {
    if (x.size() == 0)
      throw Set::TooFewArguments("Set::element");
    GECODE_POST;
    Set::Element::ElementUnion<SetView,SingletonView,SetView>::IdxViewArray
      iv(home, x);
    SetView zv(z);

    Int::IntView yv(y);
    SingletonView single(yv);
    GECODE_ES_FAIL((Element::ElementUnion<SetView,SingletonView,SetView>
      ::post(home, iv, single,zv)));
  }
Example #7
0
 SymmetryHandle VariableSequenceSymmetry(const SetVarArgs& x, int ss) {
   ArgArray<VarImpBase*> a(x.size());
   for (int i = 0 ; i < x.size() ; i++)
     a[i] = x[i].varimp();
   return SymmetryHandle(new VariableSequenceSymmetryObject(a, ss));
 }
Example #8
0
  BrancherHandle
  branch(Home home, const SetVarArgs& x,
         TieBreak<SetVarBranch> vars, SetValBranch vals,
         const Symmetries& syms, 
         SetBranchFilter bf, SetVarValPrint vvp) {
    using namespace Set;
    if (home.failed()) return BrancherHandle();
    vars.a.expand(home,x);
    if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
        (vars.a.select() == SetVarBranch::SEL_RND))
      vars.b = SET_VAR_NONE();
    vars.b.expand(home,x);
    if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
        (vars.b.select() == SetVarBranch::SEL_RND))
      vars.c = SET_VAR_NONE();
    vars.c.expand(home,x);
    if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
        (vars.c.select() == SetVarBranch::SEL_RND))
      vars.d = SET_VAR_NONE();
    vars.d.expand(home,x);
    if (vars.b.select() == SetVarBranch::SEL_NONE) {
      return branch(home,x,vars.a,vals,syms,bf,vvp);
    } else {
      // Construct mapping from each variable in the array to its index
      // in the array.
      VariableMap variableMap;
      for (int i = 0 ; i < x.size() ; i++)
        variableMap[x[i].varimp()] = i;
      
      // Convert the modelling-level Symmetries object into an array of
      // SymmetryImp objects.
      int n = syms.size();
      SymmetryImp<SetView>** array =
        static_cast<Space&>(home).alloc<SymmetryImp<SetView>* >(n);
      for (int i = 0 ; i < n ; i++) {
        array[i] = Set::LDSB::createSetSym(home, syms[i], variableMap);
      }

      ViewArray<SetView> xv(home,x);
      ValSelCommitBase<SetView,int>* vsc = Branch::valselcommit(home,vals); 
      if (vars.c.select() == SetVarBranch::SEL_NONE) {
        ViewSel<SetView>* vs[2] = { 
          Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
        };
        return 
          LDSBSetBrancher<SetView,2,int,2>::post(home,xv,vs,vsc,array,n,bf,vvp);
      } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
        ViewSel<SetView>* vs[3] = { 
          Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
          Branch::viewsel(home,vars.c)
        };
        return 
          LDSBSetBrancher<SetView,3,int,2>::post(home,xv,vs,vsc,array,n,bf,vvp);
      } else {
        ViewSel<SetView>* vs[4] = { 
          Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
          Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
        };
        return 
          LDSBSetBrancher<SetView,4,int,2>::post(home,xv,vs,vsc,array,n,bf,vvp);
      }
    }
  }
Example #9
0
  void
  branch(Gecode::Home home, const SetVarArgs& x,
         const Gecode::TieBreakVarBranch<SetVarBranch>& vars,
         SetValBranch vals,
         const Gecode::TieBreakVarBranchOptions& o_vars,
         const Gecode::ValBranchOptions& o_vals) {
    using namespace Gecode;
    using namespace Gecode::Set;
    using namespace Gecode::Set::Branch;


    if (home.failed()) return;
    if ((vars.a == SET_VAR_NONE) || (vars.a == SET_VAR_RND) ||
        ((vars.b == SET_VAR_NONE) && (vars.c == SET_VAR_NONE) && (vars.d == SET_VAR_NONE))) {
      branch(home,x,vars.a,vals,o_vars.a,o_vals);
      return;
    }
    if (o_vars.a.activity.initialized() &&
        (o_vars.a.activity.size() != x.size()))
      throw ActivityWrongArity("branch (option a)");
    if (o_vars.b.activity.initialized() &&
        (o_vars.b.activity.size() != x.size()))
      throw ActivityWrongArity("branch (option b)");
    if (o_vars.c.activity.initialized() &&
        (o_vars.c.activity.size() != x.size()))
      throw ActivityWrongArity("branch (option c)");
    if (o_vars.d.activity.initialized() &&
        (o_vars.d.activity.size() != x.size()))
      throw ActivityWrongArity("branch (option d)");
    ViewArray<SetView> xv(home,x);
    Gecode::ViewSelVirtualBase<SetView>* tb[3];
    int n=0;
    if (vars.b != SET_VAR_NONE)
      virtualize(home,vars.b,o_vars.b,tb[n++]);
    if (vars.c != SET_VAR_NONE)
      virtualize(home,vars.c,o_vars.c,tb[n++]);
    if (vars.d != SET_VAR_NONE)
      virtualize(home,vars.d,o_vars.d,tb[n++]);
    assert(n > 0);
    ViewSelTieBreakDynamic<SetView> vbcd(home,tb,n);
    switch (vars.a) {
    case SET_VAR_DEGREE_MIN:
      {
        ViewSelDegreeMin<SetView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelDegreeMin<SetView>,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_DEGREE_MAX:
      {
        ViewSelDegreeMax<SetView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelDegreeMax<SetView>,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_AFC_MIN:
      {
        ViewSelAfcMin<SetView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelAfcMin<SetView>,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_AFC_MAX:
      {
        ViewSelAfcMax<SetView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelAfcMax<SetView>,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_ACTIVITY_MIN:
      {
        ViewSelActivityMin<SetView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelActivityMin<SetView>,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_ACTIVITY_MAX:
      {
        ViewSelActivityMax<SetView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelActivityMax<SetView>,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_MIN_MIN:
      {
        ByMinMin va(home,o_vars.a);
        ViewSelTieBreakStatic<ByMinMin,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_MIN_MAX:
      {
        ByMinMin va(home,o_vars.a);
        ViewSelTieBreakStatic<ByMinMin,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_MAX_MIN:
      {
        ByMaxMin va(home,o_vars.a);
        ViewSelTieBreakStatic<ByMaxMin,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_MAX_MAX:
      {
        ByMaxMax va(home,o_vars.a);
        ViewSelTieBreakStatic<ByMaxMax,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_SIZE_MIN:
      {
        BySizeMin va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeMin,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_SIZE_MAX:
      {
        BySizeMax va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeMax,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_SIZE_DEGREE_MIN:
      {
        BySizeDegreeMin va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeDegreeMin,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_SIZE_DEGREE_MAX:
      {
        BySizeDegreeMax va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeDegreeMax,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_SIZE_AFC_MIN:
      {
        BySizeAfcMin va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeAfcMin,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_SIZE_AFC_MAX:
      {
        BySizeAfcMax va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeAfcMax,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_SIZE_ACTIVITY_MIN:
      {
        BySizeActivityMin va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeActivityMin,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case SET_VAR_SIZE_ACTIVITY_MAX:
      {
        BySizeActivityMax va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeActivityMax,
          ViewSelTieBreakDynamic<SetView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    default:
      throw UnknownBranching("Set::branch");
    }
  }
Example #10
0
  void
  branch(Gecode::Home home, const SetVarArgs& x,
         SetVarBranch vars, SetValBranch vals,
         const Gecode::VarBranchOptions& o_vars,
         const Gecode::ValBranchOptions& o_vals) {
    using namespace Gecode;
    using namespace Gecode::Set;
    using namespace Gecode::Set::Branch;


    if (home.failed()) return;
    if (o_vars.activity.initialized() &&
        (o_vars.activity.size() != x.size()))
      throw ActivityWrongArity("branch");
    ViewArray<SetView> xv(home,x);
    switch (vars) {
    case SET_VAR_NONE:
      {
        ViewSelNone<SetView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_RND:
      {
        ViewSelRnd<SetView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_DEGREE_MIN:
      {
        ViewSelDegreeMin<SetView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_DEGREE_MAX:
      {
        ViewSelDegreeMax<SetView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_AFC_MIN:
      {
        ViewSelAfcMin<SetView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_AFC_MAX:
      {
        ViewSelAfcMax<SetView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_ACTIVITY_MIN:
      {
        ViewSelActivityMin<SetView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_ACTIVITY_MAX:
      {
        ViewSelActivityMax<SetView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_MIN_MIN:
      {
        ByMinMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_MIN_MAX:
      {
        ByMinMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_MAX_MIN:
      {
        ByMaxMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_MAX_MAX:
      {
        ByMaxMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_SIZE_MIN:
      {
        BySizeMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_SIZE_MAX:
      {
        BySizeMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_SIZE_DEGREE_MIN:
      {
        BySizeDegreeMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_SIZE_DEGREE_MAX:
      {
        BySizeDegreeMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_SIZE_AFC_MIN:
      {
        BySizeAfcMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_SIZE_AFC_MAX:
      {
        BySizeAfcMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_SIZE_ACTIVITY_MIN:
      {
        BySizeActivityMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case SET_VAR_SIZE_ACTIVITY_MAX:
      {
        BySizeActivityMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    default:
      throw UnknownBranching("Set::branch");
    }
  }