当前位置: 首页>>代码示例>>C++>>正文


C++ SizeOptions::size方法代码示例

本文整理汇总了C++中SizeOptions::size方法的典型用法代码示例。如果您正苦于以下问题:C++ SizeOptions::size方法的具体用法?C++ SizeOptions::size怎么用?C++ SizeOptions::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SizeOptions的用法示例。


在下文中一共展示了SizeOptions::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: d

  /// Actual model
  GolombRuler(const SizeOptions& opt)
    : IntMinimizeScript(opt),
      m(*this,opt.size(),0,
        (opt.size() < 31) ? (1 << (opt.size()-1))-1 : Int::Limits::max) {

    // Assume first mark to be zero
    rel(*this, m[0], IRT_EQ, 0);

    // Order marks
    rel(*this, m, IRT_LE);

    // Number of marks and differences
    const int n = m.size();
    const int n_d = (n*n-n)/2;

    // Array of differences
    IntVarArgs d(n_d);

    // Setup difference constraints
    for (int k=0, i=0; i<n-1; i++)
      for (int j=i+1; j<n; j++, k++)
        // d[k] is m[j]-m[i] and must be at least sum of first j-i integers
        rel(*this, d[k] = expr(*this, m[j]-m[i]),
                   IRT_GQ, (j-i)*(j-i+1)/2);

    distinct(*this, d, opt.icl());

    // Symmetry breaking
    if (n > 2)
      rel(*this, d[0], IRT_LE, d[n_d-1]);

    branch(*this, m, INT_VAR_NONE(), INT_VAL_MIN());
  }
开发者ID:Wushaowei001,项目名称:gecode-profiling,代码行数:34,代码来源:golomb-ruler.cpp

示例2: costs

  SetCovering(const SizeOptions& opt) 
  : 
    x(*this, num_alternatives, 0, 1),
    z(*this, 0, 999999)
  {

    // costs per alternative
    int _costs[] = {19, 16, 18, 13, 15, 19, 15, 17, 16, 15};
    IntArgs costs(num_alternatives, _costs);

    // the alternatives and the objects they contain
    int _a[] = {
   // 1 2 3 4 5 6 7 8  the objects 
      1,0,0,0,0,1,0,0,  // alternative 1
      0,1,0,0,0,1,0,1,  // alternative 2
      1,0,0,1,0,0,1,0,  // alternative 3
      0,1,1,0,1,0,0,0,  // alternative 4
      0,1,0,0,1,0,0,0,  // alternative 5
      0,1,1,0,0,0,0,0,  // alternative 6
      0,1,1,1,0,0,0,0,  // alternative 7
      0,0,0,1,1,0,0,1,  // alternative 8
      0,0,1,0,0,1,0,1,  // alternative 9
      1,0,0,0,0,1,1,0,  // alternative 10
    };
    IntArgs a(num_alternatives*num_objects, _a);


    for(int j = 0; j < num_objects; j++) {
      IntVarArgs tmp; 
      for(int i = 0; i < num_alternatives; i++) {
        tmp << expr(*this, x[i]*a[i*num_objects+j]);
      }
      if (opt.size() == 0) {
        // set partition problem:
        // objects must be covered _exactly_ once
        rel(*this, sum(tmp) == 1);
      } else {
        // set covering problem
        // all objects must be covered _at least_ once
        rel(*this, sum(tmp) >= 1);
      }      
    }

    if (opt.search() == SEARCH_DFS) {
      if (opt.size() == 0) {
        rel(*this, z <= 49);
      } else {
        rel(*this, z <= 45);
      }
    }
    
    linear(*this, costs, x, IRT_EQ, z);

    branch(*this, x, INT_VAR_NONE(), INT_VAL_MIN()); 

  }
开发者ID:HanumathRao,项目名称:hakank,代码行数:56,代码来源:set_covering4.cpp

示例3: QueenArmies

  /// Constructor
  QueenArmies(const SizeOptions& opt) :
    n(opt.size()),
    U(*this, IntSet::empty, IntSet(0, n*n)),
    W(*this, IntSet::empty, IntSet(0, n*n)),
    w(*this, n*n, 0, 1),
    b(*this, n*n, 0, 1),
    q(*this, 0, n*n)
  {
    // Basic rules of the model
    for (int i = n*n; i--; ) {
      // w[i] means that no blacks are allowed on A[i]
      rel(*this, w[i] == (U || A[i]));
      // Make sure blacks and whites are disjoint.
      rel(*this, !w[i] || !b[i]);
      // If i in U, then b[i] has a piece.
      rel(*this, b[i] == (singleton(i) <= U));
    }

    // Connect optimization variable to number of pieces
    linear(*this, w, IRT_EQ, q);
    linear(*this, b, IRT_GQ, q);

    // Connect cardinality of U to the number of black pieces.
    IntVar unknowns = expr(*this, cardinality(U));
    rel(*this, q <= unknowns);
    linear(*this, b, IRT_EQ, unknowns);

    if (opt.branching() == BRANCH_NAIVE) {
      branch(*this, w, INT_VAR_NONE, INT_VAL_MAX);
      branch(*this, b, INT_VAR_NONE, INT_VAL_MAX);
    } else {
      QueenBranch::post(*this);
      assign(*this, b, INT_ASSIGN_MAX);
    }
  }
开发者ID:lquan,项目名称:CSAI,代码行数:36,代码来源:queen-armies.cpp

示例4: c

  /// Actual model
  TSP(const SizeOptions& opt)
    : p(ps[opt.size()]),
      succ(*this, p.size(), 0, p.size()-1),
      total(*this, 0, p.max()) {
    int n = p.size();

    // Cost matrix
    IntArgs c(n*n, p.d());

    for (int i=n; i--; )
      for (int j=n; j--; )
        if (p.d(i,j) == 0)
          rel(*this, succ[i], IRT_NQ, j);

    // Cost of each edge
    IntVarArgs costs(*this, n, Int::Limits::min, Int::Limits::max);

    // Enforce that the succesors yield a tour with appropriate costs
    circuit(*this, c, succ, costs, total, opt.icl());

    // Just assume that the circle starts forwards
    {
      IntVar p0(*this, 0, n-1);
      element(*this, succ, p0, 0);
      rel(*this, p0, IRT_LE, succ[0]);
    }

    // First enumerate cost values, prefer those that maximize cost reduction
    branch(*this, costs, INT_VAR_REGRET_MAX_MAX(), INT_VAL_SPLIT_MIN());

    // Then fix the remaining successors
    branch(*this, succ,  INT_VAR_MIN_MIN(), INT_VAL_MIN());
  }
开发者ID:Wushaowei001,项目名称:gecode-clone,代码行数:34,代码来源:tsp.cpp

示例5: variables

  Coins3(const SizeOptions& opt) 
  : 
    num_coins_val(opt.size()),
    x(*this, n, 0, 99),
    num_coins(*this, 0, 99)
  {

    // values of the coins
    int _variables[] = {1, 2, 5, 10, 25, 50}; 
    IntArgs variables(n, _variables); 

    // sum the number of coins
    linear(*this, x, IRT_EQ, num_coins, opt.icl());

    // This is the "main loop":
    // Checks that all changes from 1 to 99 can be made
    for(int j = 0; j < 99; j++) {
      IntVarArray tmp(*this, n, 0, 99);
      linear(*this, variables, tmp, IRT_EQ, j, opt.icl());
      for(int i = 0; i < n; i++) {
        rel(*this, tmp[i] <= x[i], opt.icl());
      }
    }

    // set the number of coins (via opt.size())
    // don't forget 
    //  -search dfs
    if (num_coins_val) {
      rel(*this, num_coins == num_coins_val, opt.icl());
    }

    branch(*this, x, INT_VAR_SIZE_MAX(), INT_VAL_MIN()); 

  }
开发者ID:HanumathRao,项目名称:hakank,代码行数:34,代码来源:coins3.cpp

示例6: viol

  /// Actual model
  Photo(const SizeOptions& opt) :
    IntMinimizeScript(opt),
    spec(opt.size() == 0 ? p_small : p_large),
    pos(*this,spec.n_names, 0, spec.n_names-1),
    violations(*this,0,spec.n_prefs)
  {
    // Map preferences to violation
    BoolVarArgs viol(spec.n_prefs);
    for (int i=0; i<spec.n_prefs; i++) {
      int pa = spec.prefs[2*i+0];
      int pb = spec.prefs[2*i+1];
      viol[i] = expr(*this, abs(pos[pa]-pos[pb]) > 1);
    }
    rel(*this, violations == sum(viol));

    distinct(*this, pos, opt.icl());

    // Break some symmetries
    rel(*this, pos[0] < pos[1]);

    if (opt.branching() == BRANCH_NONE) {
      branch(*this, pos, INT_VAR_NONE(), INT_VAL_MIN());
    } else {
      branch(*this, pos, tiebreak(INT_VAR_DEGREE_MAX(),INT_VAR_SIZE_MIN()),
             INT_VAL_MIN());
    }
  }
开发者ID:Wushaowei001,项目名称:vcp,代码行数:28,代码来源:photo.cpp

示例7: AllInterval

  /// Actual model
  AllInterval(const SizeOptions& opt) :
    x(*this, opt.size(), 0, opt.size()-1),
    d(*this, opt.size()-1, 1, opt.size()-1) {
    const int n = x.size();

    // Set up variables for distance
    for (int i=0; i<n-1; i++)
      rel(*this, d[i] == abs(x[i+1]-x[i]), opt.icl());

    distinct(*this, x, opt.icl());
    distinct(*this, d, opt.icl());

    // Break mirror symmetry
    rel(*this, x[0], IRT_LE, x[1]);
    // Break symmetry of dual solution
    rel(*this, d[0], IRT_GR, d[n-2]);

    branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN());
  }
开发者ID:tkelman,项目名称:gecode,代码行数:20,代码来源:all-interval.cpp

示例8: z

  /// Actual model
  OrthoLatinSquare(const SizeOptions& opt)
    : Script(opt),
      n(opt.size()),
      x1(*this,n*n,1,n), x2(*this,n*n,1,n) {
    const int nn = n*n;
    IntVarArgs z(*this,nn,0,n*n-1);

    distinct(*this, z, opt.icl());
    // Connect
    {
      IntArgs mod(n*n);
      IntArgs div(n*n);
      for (int i=0; i<n; i++)
        for (int j=0; j<n; j++) {
          mod[i*n+j] = j+1;
          div[i*n+j] = i+1;
        }
      for (int i = nn; i--; ) {
        element(*this, div, z[i], x2[i]);
        element(*this, mod, z[i], x1[i]);
      }
    }

    // Rows
    for (int i = n; i--; ) {
      IntVarArgs ry(n);
      for (int j = n; j--; )
        ry[j] = y1(i,j);
      distinct(*this, ry, opt.icl());
      for (int j = n; j--; )
        ry[j] = y2(i,j);
      distinct(*this, ry, opt.icl());
    }
    for (int j = n; j--; ) {
      IntVarArgs cy(n);
      for (int i = n; i--; )
        cy[i] = y1(i,j);
      distinct(*this, cy, opt.icl());
      for (int i = n; i--; )
        cy[i] = y2(i,j);
      distinct(*this, cy, opt.icl());
    }

    for (int i = 1; i<n; i++) {
      IntVarArgs ry1(n);
      IntVarArgs ry2(n);
      for (int j = n; j--; ) {
        ry1[j] = y1(i-1,j);
        ry2[j] = y2(i,j);
      }
      rel(*this, ry1, IRT_GQ, ry2);
    }

    branch(*this, z, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN());
  }
开发者ID:Wushaowei001,项目名称:vcp,代码行数:56,代码来源:ortho-latin.cpp

示例9: Queens

 /// The actual problem
 Queens(const SizeOptions& opt)
   : q(*this,opt.size(),0,opt.size()-1) {
   const int n = q.size();
   switch (opt.propagation()) {
   case PROP_BINARY:
     for (int i = 0; i<n; i++)
       for (int j = i+1; j<n; j++) {
         rel(*this, q[i] != q[j]);
         rel(*this, q[i]+i != q[j]+j);
         rel(*this, q[i]-i != q[j]-j);
       }
     break;
   case PROP_MIXED:
     for (int i = 0; i<n; i++)
       for (int j = i+1; j<n; j++) {
         rel(*this, q[i]+i != q[j]+j);
         rel(*this, q[i]-i != q[j]-j);
       }
     distinct(*this, q, opt.icl());
     break;
   case PROP_DISTINCT:
     distinct(*this, IntArgs::create(n,0,1), q, opt.icl());
     distinct(*this, IntArgs::create(n,0,-1), q, opt.icl());
     distinct(*this, q, opt.icl());
     break;
   }
   switch(opt.branching()) {
   case BRANCH_MIN:
       branch(*this, q, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
       break;
   case BRANCH_MID:
     branch(*this, q, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
     break;
   case BRANCH_MAX_MAX:
     branch(*this, q, INT_VAR_SIZE_MAX(), INT_VAL_MIN());
     break;
   case BRANCH_KNIGHT_MOVE:
     branch(*this, q, INT_VAR_MIN_MIN(), INT_VAL_MED());
     break;
   }
 }
开发者ID:SteveLTN,项目名称:CPAss,代码行数:42,代码来源:queens.cpp

示例10: xy

  /// Actual model
  Partition(const SizeOptions& opt)
    : x(*this,opt.size(),1,2*opt.size()),
      y(*this,opt.size(),1,2*opt.size()) {
    const int n = opt.size();

    // Break symmetries by ordering numbers in each group
    rel(*this, x, IRT_LE);
    rel(*this, y, IRT_LE);

    rel(*this, x[0], IRT_LE, y[0]);

    IntVarArgs xy(2*n);
    for (int i = n; i--; ) {
      xy[i] = x[i]; xy[n+i] = y[i];
    }
    distinct(*this, xy, opt.icl());

    IntArgs c(2*n);
    for (int i = n; i--; ) {
      c[i] = 1; c[n+i] = -1;
    }
    linear(*this, c, xy, IRT_EQ, 0);

    // Array of products
    IntVarArgs sxy(2*n), sx(n), sy(n);

    for (int i = n; i--; ) {
      sx[i] = sxy[i] =   expr(*this, sqr(x[i]));
      sy[i] = sxy[n+i] = expr(*this, sqr(y[i]));
    }
    linear(*this, c, sxy, IRT_EQ, 0);

    // Redundant constraints
    linear(*this, x, IRT_EQ, 2*n*(2*n+1)/4);
    linear(*this, y, IRT_EQ, 2*n*(2*n+1)/4);
    linear(*this, sx, IRT_EQ, 2*n*(2*n+1)*(4*n+1)/12);
    linear(*this, sy, IRT_EQ, 2*n*(2*n+1)*(4*n+1)/12);

    branch(*this, xy, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
  }
开发者ID:Wushaowei001,项目名称:gecode-clone,代码行数:41,代码来源:partition.cpp

示例11: _dur

    /// The actual problem
    OpenShop(const SizeOptions& opt)
        : spec(examples[opt.size()]),
          b(*this, (spec.n+spec.m-2)*spec.n*spec.m/2, 0,1),
          makespan(*this, 0, Int::Limits::max),
          _start(*this, spec.m*spec.n, 0, Int::Limits::max) {

        Matrix<IntVarArray> start(_start, spec.m, spec.n);
        IntArgs _dur(spec.m*spec.n, spec.p);
        Matrix<IntArgs> dur(_dur, spec.m, spec.n);

        int minmakespan;
        int maxmakespan;
        crosh(dur, minmakespan, maxmakespan);
        rel(*this, makespan <= maxmakespan);
        rel(*this, makespan >= minmakespan);

        int k=0;
        for (int m=0; m<spec.m; m++)
            for (int j0=0; j0<spec.n-1; j0++)
                for (int j1=j0+1; j1<spec.n; j1++) {
                    // The tasks on machine m of jobs j0 and j1 must be disjoint
                    rel(*this,
                        b[k] == (start(m,j0) + dur(m,j0) <= start(m,j1)));
                    rel(*this,
                        b[k++] == (start(m,j1) + dur(m,j1) > start(m,j0)));
                }

        for (int j=0; j<spec.n; j++)
            for (int m0=0; m0<spec.m-1; m0++)
                for (int m1=m0+1; m1<spec.m; m1++) {
                    // The tasks in job j on machine m0 and m1 must be disjoint
                    rel(*this,
                        b[k] == (start(m0,j) + dur(m0,j) <= start(m1,j)));
                    rel(*this,
                        b[k++] == (start(m1,j) + dur(m1,j) > start(m0,j)));
                }

        // The makespan is greater than the end time of the latest job
        for (int m=0; m<spec.m; m++) {
            for (int j=0; j<spec.n; j++) {
                rel(*this, start(m,j) + dur(m,j) <= makespan);
            }
        }

        // First branch over the precedences
        branch(*this, b, INT_VAR_AFC_MAX, INT_VAL_MAX);
        // When the precedences are fixed, simply assign the start times
        assign(*this, _start, INT_ASSIGN_MIN);
        // When the start times are fixed, use the tightest makespan
        assign(*this, makespan, INT_ASSIGN_MIN);
    }
开发者ID:emosei,项目名称:chef,代码行数:52,代码来源:open-shop.cpp

示例12: black

  /// The actual problem
  Kakuro(const SizeOptions& opt)
    : w(examples[opt.size()][0]),  h(examples[opt.size()][1]),
      f(*this,w*h) {
    IntVar black(*this,0,0);
    // Initialize all fields as black (unused). Only if a field
    // is actually used in a constraint, create a fresh variable
    // for it (done via init).
    for (int i=w*h; i--; )
      f[i] = black;

    // Cache of already computed tuple sets
    Cache cache;

    // Matrix for accessing board fields
    Matrix<IntVarArray> b(f,w,h);
    // Access to hints
    const int* k = &examples[opt.size()][2];

    // Process vertical hints
    while (*k >= 0) {
      int x=*k++; int y=*k++; int n=*k++; int s=*k++;
      IntVarArgs col(n);
      for (int i=n; i--; )
        col[i]=init(b(x,y+i+1));
      distinctlinear(cache,col,s,opt);
    }
    k++;

    // Process horizontal hints
    while (*k >= 0) {
      int x=*k++; int y=*k++; int n=*k++; int s=*k++;
      IntVarArgs row(n);
      for (int i=n; i--; )
        row[i]=init(b(x+i+1,y));
      distinctlinear(cache,row,s,opt);
    }
    branch(*this, f, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_SPLIT_MIN());
  }
开发者ID:Wushaowei001,项目名称:gecode-clone,代码行数:39,代码来源:kakuro.cpp

示例13: d

  /// Actual model
  AllInterval(const SizeOptions& opt) :
    x(*this, opt.size(), 0, opt.size() - 1) {
    const int n = x.size();

    IntVarArgs d(n-1);

    // Set up variables for distance
    for (int i=0; i<n-1; i++)
      d[i] = expr(*this, abs(x[i+1]-x[i]), opt.icl());

    // Constrain them to be between 1 and n-1
    dom(*this, d, 1, n-1);

    distinct(*this, x, opt.icl());
    distinct(*this, d, opt.icl());

    // Break mirror symmetry
    rel(*this, x[0], IRT_LE, x[1]);
    // Break symmetry of dual solution
    rel(*this, d[0], IRT_GR, d[n-2]);

    branch(*this, x, INT_VAR_SIZE_MIN, INT_VAL_SPLIT_MIN);
  }
开发者ID:YoshihisaMaruya,项目名称:tool_test_chef,代码行数:24,代码来源:all-interval.cpp

示例14: Calculs

  /// Actual model
  Calculs(const SizeOptions& opt) : 
    X(*this, N, -N, N),
    X_abs(*this, N, 0, N),
    x_max(*this, 0, N),
    show_all(opt.size())
  {

    IntVar
      a(X[ 0]), b(X[ 1]), c(X[ 2]), e(X[ 4]), f(X[ 5]),
      g(X[ 6]), h(X[ 7]), i(X[ 8]), j(X[ 9]), k(X[10]),
      l(X[11]), m(X[12]), n(X[13]), o(X[14]), p(X[15]),
      q(X[16]), r(X[17]), s(X[18]), t(X[19]), u(X[20]),
      v(X[21]), w(X[22]), x(X[23]), y(X[24]), z(X[25]);


    // x_max is the max value of abs(X)   
    for(int i = 0; i < N; i++)  {
      abs(*this, X[i], X_abs[i], opt.icl());
    }
    max(*this, X_abs, x_max, opt.icl());

    rel(*this, z+e+r+o     == 0, opt.icl());
    rel(*this, o+n+e       == 1, opt.icl());
    rel(*this, t+w+o       == 2, opt.icl());
    rel(*this, t+h+r+e+e   == 3, opt.icl());
    rel(*this, f+o+u+r     == 4, opt.icl());
    rel(*this, f+i+v+e     == 5, opt.icl());
    rel(*this, s+i+x       == 6, opt.icl());
    rel(*this, s+e+v+e+n   == 7, opt.icl());
    rel(*this, e+i+g+h+t   == 8, opt.icl());
    rel(*this, n+i+n+e     == 9, opt.icl());
    rel(*this, t+e+n       == 10, opt.icl());
    rel(*this, e+l+e+v+e+n == 11, opt.icl());
    rel(*this, t+w+e+l+f   == 12, opt.icl());

    distinct(*this, X, opt.icl());

    // for showing all solutions (there are many)
    if (show_all) {
      rel(*this, x_max == 16, opt.icl());
    }

    branch(*this, X, INT_VAR_DEGREE_MAX(), INT_VAL_MIN());

  }
开发者ID:HanumathRao,项目名称:hakank,代码行数:46,代码来源:calculs_d_enfer.cpp

示例15: MineSweeper

    /// Actual model
    MineSweeper(const SizeOptions& opt)
        : spec(specs[opt.size()]),
          size(spec_size(spec)),
          b(*this,size*size,0,1) {
        Matrix<BoolVarArray> m(b, size, size);

        // Initialize matrix and post constraints
        for (int h=0; h<size; h++)
            for (int w=0; w<size; w++) {
                int v = mineField(spec, size, h, w);
                if (v != -1) {
                    rel(*this, m(w, h), IRT_EQ, 0);
                    linear(*this, fieldsAround(m, w, h), IRT_EQ, v);
                }
            }

        // Install branching
        branch(*this, b, INT_VAR_NONE(), INT_VAL_MAX());
    }
开发者ID:Wushaowei001,项目名称:gecode-clone,代码行数:20,代码来源:minesweeper.cpp


注:本文中的SizeOptions::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。