本文整理汇总了C++中SizeOptions::icl方法的典型用法代码示例。如果您正苦于以下问题:C++ SizeOptions::icl方法的具体用法?C++ SizeOptions::icl怎么用?C++ SizeOptions::icl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SizeOptions
的用法示例。
在下文中一共展示了SizeOptions::icl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: x
Sudoku(const SizeOptions& opt) : x(*this, 9 * 9, 1, 9) {
Matrix<IntVarArray> m(x, 9, 9);
for (int i = 0; i < 9; i++) {
distinct(*this, m.row(i), opt.icl());
distinct(*this, m.col(i), opt.icl());
}
for (int i = 0; i < 9; i += 3) {
for (int j = 0; j < 9; j += 3) {
distinct(*this, m.slice(i, i + 3, j, j + 3), opt.icl());
}
}
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
if (int v = sudokuField(board, i, j)) {
//Here the m(i, j) is the element in colomn i and row j.
rel(*this, m(i, j), IRT_EQ, v);
}
}
}
branch(*this, x, INT_VAR_NONE(), INT_VAL_SPLIT_MIN());
}
示例2: 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());
}
示例3: 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());
}
示例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());
}
示例5: 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());
}
}
示例6: 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());
}
示例7: distinctlinear
/// Post a distinct-linear constraint on variables \a x with sum \a c
void distinctlinear(Cache& dc, const IntVarArgs& x, int c,
const SizeOptions& opt) {
int n=x.size();
if (opt.model() == MODEL_DECOMPOSE) {
if (n < 8)
linear(*this, x, IRT_EQ, c, opt.icl());
else if (n == 8)
rel(*this, x, IRT_NQ, 9*(9+1)/2 - c);
distinct(*this, x, opt.icl());
} else {
switch (n) {
case 0:
return;
case 1:
rel(*this, x[0], IRT_EQ, c);
return;
case 8:
// Prune the single missing digit
rel(*this, x, IRT_NQ, 9*(9+1)/2 - c);
break;
case 9:
break;
default:
if (c == n*(n+1)/2) {
// sum has unique decomposition: 1 + ... + n
rel(*this, x, IRT_LQ, n);
} else if (c == n*(n+1)/2 + 1) {
// sum has unique decomposition: 1 + ... + n-1 + n+1
rel(*this, x, IRT_LQ, n+1);
rel(*this, x, IRT_NQ, n);
} else if (c == 9*(9+1)/2 - (9-n)*(9-n+1)/2) {
// sum has unique decomposition: (9-n+1) + (9-n+2) + ... + 9
rel(*this, x, IRT_GQ, 9-n+1);
} else if (c == 9*(9+1)/2 - (9-n)*(9-n+1)/2 + 1) {
// sum has unique decomposition: (9-n) + (9-n+2) + ... + 9
rel(*this, x, IRT_GQ, 9-n);
rel(*this, x, IRT_NQ, 9-n+1);
} else {
extensional(*this, x, dc.get(n,c));
return;
}
}
distinct(*this, x, opt.icl());
}
}
示例8: LatinSquares
LatinSquares(const SizeOptions& opt)
:
n(opt.size()),
x(*this, n*n, 1, n) {
// Matrix wrapper for the x grid
Matrix<IntVarArray> m(x, n, n);
latin_square(*this, m, opt.icl());
// Symmetry breaking. 0 is upper left column
if (opt.symmetry() == SYMMETRY_MIN) {
rel(*this, x[0] == 1, opt.icl());
}
branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_RANGE_MAX());
}
示例9: 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());
}
示例10: AllEqual
// Actual model
AllEqual(const SizeOptions& opt) :
x(*this, n, 0, 6)
{
all_equal(*this, x, n, opt.icl());
// branching
branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
}
示例11: 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;
}
}
示例12: in_distance
SetCovering(const SizeOptions& opt)
:
min_distance(opt.size()),
x(*this, num_cities, 0, 1),
z(*this, 0, num_cities)
{
// distance between the cities
int distance[] =
{
0,10,20,30,30,20,
10, 0,25,35,20,10,
20,25, 0,15,30,20,
30,35,15, 0,15,25,
30,20,30,15, 0,14,
20,10,20,25,14, 0
};
// z = sum of placed fire stations
linear(*this, x, IRT_EQ, z, opt.icl());
// ensure that all cities are covered by at least one fire station
for(int i = 0; i < num_cities; i++) {
IntArgs in_distance(num_cities); // the cities within the distance
for(int j = 0; j < num_cities; j++) {
if (distance[i*num_cities+j] <= min_distance) {
in_distance[j] = 1;
} else {
in_distance[j] = 0;
}
}
linear(*this, in_distance, x, IRT_GQ, 1, opt.icl());
}
branch(*this, x, INT_VAR_SIZE_MAX(), INT_VAL_SPLIT_MIN());
}
示例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);
}
示例14: MagicSquare
/// Post constraints
MagicSquare(const SizeOptions& opt)
: n(opt.size()), x(*this,n*n,1,n*n) {
// Number of fields on square
const int nn = n*n;
// Sum of all a row, column, or diagonal
const int s = nn*(nn+1) / (2*n);
// Matrix-wrapper for the square
Matrix<IntVarArray> m(x, n, n);
for (int i = n; i--; ) {
linear(*this, m.row(i), IRT_EQ, s, opt.icl());
linear(*this, m.col(i), IRT_EQ, s, opt.icl());
}
// Both diagonals must have sum s
{
IntVarArgs d1y(n);
IntVarArgs d2y(n);
for (int i = n; i--; ) {
d1y[i] = m(i,i);
d2y[i] = m(n-i-1,i);
}
linear(*this, d1y, IRT_EQ, s, opt.icl());
linear(*this, d2y, IRT_EQ, s, opt.icl());
}
// All fields must be distinct
distinct(*this, x, opt.icl());
// Break some (few) symmetries
rel(*this, m(0,0), IRT_GR, m(0,n-1));
rel(*this, m(0,0), IRT_GR, m(n-1,0));
branch(*this, x, INT_VAR_SIZE_MIN, INT_VAL_SPLIT_MIN);
}
示例15: AlldifferentCst
// Actual model
AlldifferentCst(const SizeOptions& opt) :
x(*this, n, 1, 9),
cst(*this, n, 0, 9)
{
int _cst1[] = {0,1,0,4};
IntArgs cst1(n, _cst1);
for(int i = 0; i < n; i++) {
rel(*this, cst[i] == cst1[i]);
}
alldifferent_cst(*this, x, cst, n, opt.icl());
// branching
branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_MIN());
}