예제 #1
0
파일: linear.cpp 프로젝트: MGKhKhD/easy-IP
 void
 linear(Home home,
        const FloatVarArgs& x, FloatRelType frt, FloatNum c, Reify r) {
   using namespace Float;
   if (home.failed()) return;
   Region re(home);
   Linear::Term* t = re.alloc<Linear::Term>(x.size());
   for (int i = x.size(); i--; ) {
     t[i].a=1.0; t[i].x=x[i];
   }
   Linear::post(home,t,x.size(),frt,c,r);
 }
예제 #2
0
 void
 min(Home home, const FloatVarArgs& x, FloatVar y) {
   using namespace Float;
   if (x.size() == 0)
     throw TooFewArguments("Float::min");
   if (home.failed()) return;
   ViewArray<MinusView> m(home,x.size());
   for (int i=x.size(); i--; )
     m[i] = MinusView(x[i]);
   MinusView my(y);
   GECODE_ES_FAIL(Arithmetic::NaryMax<MinusView>::post(home,m,my));
 }
예제 #3
0
파일: linear.cpp 프로젝트: MGKhKhD/easy-IP
 void
 linear(Home home,
        const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt, 
        FloatNum c, Reify r) {
   using namespace Float;
   if (a.size() != x.size())
     throw ArgumentSizeMismatch("Float::linear");
   if (home.failed()) return;
   Region re(home);
   Linear::Term* t = re.alloc<Linear::Term >(x.size());
   for (int i = x.size(); i--; ) {
     t[i].a=a[i]; t[i].x=x[i];
   }
   Linear::post(home,t,x.size(),frt,c,r);
 }
예제 #4
0
파일: linear.cpp 프로젝트: MGKhKhD/easy-IP
 void
 linear(Home home,
        const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt, 
        FloatVar y) {
   using namespace Float;
   if (a.size() != x.size())
     throw ArgumentSizeMismatch("Float::linear");
   if (home.failed()) return;
   Region re(home);
   Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
   for (int i = x.size(); i--; ) {
     t[i].a=a[i]; t[i].x=x[i];
   }
   FloatNum min, max;
   estimate(t,x.size(),0.0,min,max);
   FloatView v(y);
   switch (frt) {
   case FRT_EQ:
     GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
     break;
   case FRT_GQ: case FRT_GR:
     GECODE_ME_FAIL(v.lq(home,max));
     break;
   case FRT_LQ: case FRT_LE:
     GECODE_ME_FAIL(v.gq(home,min));
     break;
   default: ;
   }
   if (home.failed()) return;
   t[x.size()].a=-1.0; t[x.size()].x=y;
   Linear::post(home,t,x.size()+1,frt,0.0);
 }
예제 #5
0
 void
 max(Home home, const FloatVarArgs& x, FloatVar y) {
   using namespace Float;
   if (x.size() == 0)
     throw TooFewArguments("Float::max");
   if (home.failed()) return;
   ViewArray<FloatView> xv(home,x);
   GECODE_ES_FAIL(Arithmetic::NaryMax<FloatView>::post(home,xv,y));
 }
예제 #6
0
  void
  branch(Gecode::Home home, const FloatVarArgs& x,
         const Gecode::TieBreakVarBranch<FloatVarBranch>& vars,
         FloatValBranch vals,
         const Gecode::TieBreakVarBranchOptions& o_vars,
         const Gecode::ValBranchOptions& o_vals) {
    using namespace Gecode;
    using namespace Gecode::Float;
    using namespace Gecode::Float::Branch;


    if (home.failed()) return;
    if ((vars.a == FLOAT_VAR_NONE) || (vars.a == FLOAT_VAR_RND) ||
        ((vars.b == FLOAT_VAR_NONE) && (vars.c == FLOAT_VAR_NONE) && (vars.d == FLOAT_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<FloatView> xv(home,x);
    Gecode::ViewSelVirtualBase<FloatView>* tb[3];
    int n=0;
    if (vars.b != FLOAT_VAR_NONE)
      virtualize(home,vars.b,o_vars.b,tb[n++]);
    if (vars.c != FLOAT_VAR_NONE)
      virtualize(home,vars.c,o_vars.c,tb[n++]);
    if (vars.d != FLOAT_VAR_NONE)
      virtualize(home,vars.d,o_vars.d,tb[n++]);
    assert(n > 0);
    ViewSelTieBreakDynamic<FloatView> vbcd(home,tb,n);
    switch (vars.a) {
    case FLOAT_VAR_MIN_MIN:
      {
        ByMinMin va(home,o_vars.a);
        ViewSelTieBreakStatic<ByMinMin,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_MIN_MAX:
      {
        ByMinMax va(home,o_vars.a);
        ViewSelTieBreakStatic<ByMinMax,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_MAX_MIN:
      {
        ByMaxMin va(home,o_vars.a);
        ViewSelTieBreakStatic<ByMaxMin,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_MAX_MAX:
      {
        ByMaxMax va(home,o_vars.a);
        ViewSelTieBreakStatic<ByMaxMax,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_SIZE_MIN:
      {
        BySizeMin va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeMin,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_SIZE_MAX:
      {
        BySizeMax va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeMax,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_DEGREE_MIN:
      {
        ViewSelDegreeMin<FloatView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelDegreeMin<FloatView>,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_DEGREE_MAX:
      {
        ViewSelDegreeMax<FloatView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelDegreeMax<FloatView>,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_AFC_MIN:
      {
        ViewSelAfcMin<FloatView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelAfcMin<FloatView>,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_AFC_MAX:
      {
        ViewSelAfcMax<FloatView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelAfcMax<FloatView>,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_ACTIVITY_MIN:
      {
        ViewSelActivityMin<FloatView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelActivityMin<FloatView>,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_ACTIVITY_MAX:
      {
        ViewSelActivityMax<FloatView> va(home,o_vars.a);
        ViewSelTieBreakStatic<ViewSelActivityMax<FloatView>,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_SIZE_DEGREE_MIN:
      {
        BySizeDegreeMin va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeDegreeMin,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_SIZE_DEGREE_MAX:
      {
        BySizeDegreeMax va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeDegreeMax,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_SIZE_AFC_MIN:
      {
        BySizeAfcMin va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeAfcMin,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_SIZE_AFC_MAX:
      {
        BySizeAfcMax va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeAfcMax,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_SIZE_ACTIVITY_MIN:
      {
        BySizeActivityMin va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeActivityMin,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    case FLOAT_VAR_SIZE_ACTIVITY_MAX:
      {
        BySizeActivityMax va(home,o_vars.a);
        ViewSelTieBreakStatic<BySizeActivityMax,
          ViewSelTieBreakDynamic<FloatView> > v(home,va,vbcd);
        post(home,xv,v,vals,o_vals,o_vars.a.bf);
      }
      break;
    default:
      throw UnknownBranching("Float::branch");
    }
  }
예제 #7
0
  void
  branch(Gecode::Home home, const FloatVarArgs& x,
         FloatVarBranch vars, FloatValBranch vals,
         const Gecode::VarBranchOptions& o_vars,
         const Gecode::ValBranchOptions& o_vals) {
    using namespace Gecode;
    using namespace Gecode::Float;
    using namespace Gecode::Float::Branch;


    if (home.failed()) return;
    if (o_vars.activity.initialized() &&
        (o_vars.activity.size() != x.size()))
      throw ActivityWrongArity("branch");
    ViewArray<FloatView> xv(home,x);
    switch (vars) {
    case FLOAT_VAR_NONE:
      {
        ViewSelNone<FloatView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_RND:
      {
        ViewSelRnd<FloatView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_MIN_MIN:
      {
        ByMinMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_MIN_MAX:
      {
        ByMinMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_MAX_MIN:
      {
        ByMaxMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_MAX_MAX:
      {
        ByMaxMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_SIZE_MIN:
      {
        BySizeMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_SIZE_MAX:
      {
        BySizeMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_DEGREE_MIN:
      {
        ViewSelDegreeMin<FloatView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_DEGREE_MAX:
      {
        ViewSelDegreeMax<FloatView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_AFC_MIN:
      {
        ViewSelAfcMin<FloatView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_AFC_MAX:
      {
        ViewSelAfcMax<FloatView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_ACTIVITY_MIN:
      {
        ViewSelActivityMin<FloatView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_ACTIVITY_MAX:
      {
        ViewSelActivityMax<FloatView> v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_SIZE_DEGREE_MIN:
      {
        BySizeDegreeMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_SIZE_DEGREE_MAX:
      {
        BySizeDegreeMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_SIZE_AFC_MIN:
      {
        BySizeAfcMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_SIZE_AFC_MAX:
      {
        BySizeAfcMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_SIZE_ACTIVITY_MIN:
      {
        BySizeActivityMin v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    case FLOAT_VAR_SIZE_ACTIVITY_MAX:
      {
        BySizeActivityMax v(home,o_vars);
        post(home,xv,v,vals,o_vals,o_vars.bf);
      }
      break;
    default:
      throw UnknownBranching("Float::branch");
    }
  }