sudoku(rand_obj* parent = 0) : rand_obj(parent) { // constraint possible_values, only number from 1 to 9 are allowed short numbers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) constraint(inside(field[i][j](), numbers)); // constraint rows, every number must appear exactly one time in one row for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) for (int k = j + 1; k < 9; k++) constraint(field[i][j]() != field[i][k]()); // constraint columns, every number must appear exactly one time in one column for (int j = 0; j < 9; j++) for (int i = 0; i < 9; i++) for (int k = i + 1; k < 9; k++) constraint(field[i][j]() != field[k][j]()); // constraint regions, every number must appear exactly one time in one region for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) constraint(field[i][j]() != field[(i + 1) % 3 + i - (i % 3)][j]())(field[i][j]() != field[(i + 2) % 3 + i - (i % 3)][j]()) (field[i][j]() != field[i][(j + 1) % 3 + j - (j % 3)]())( field[i][j]() != field[(i + 1) % 3 + i - (i % 3)][(j + 1) % 3 + j - (j % 3)]())( field[i][j]() != field[(i + 2) % 3 + i - (i % 3)][(j + 1) % 3 + j - (j % 3)]()) (field[i][j]() != field[i][(j + 2) % 3 + j - (j % 3)]())( field[i][j]() != field[(i + 1) % 3 + i - (i % 3)][(j + 2) % 3 + j - (j % 3)]())( field[i][j]() != field[(i + 2) % 3 + i - (i % 3)][(j + 2) % 3 + j - (j % 3)]()); }
my_rand_obj(rand_obj* parent = 0) : rand_obj(parent), car(this), color(this), power(this), price(this) { constraint(if_then(car() == AUDI, color() != GREEN)); constraint(if_then(car() == BMW, color() != RED)); constraint(if_then(car() == MERCEDES, color() != BLUE)); constraint(80 <= power() && power() <= 400); constraint(if_then(car() == BMW, power() >= 200)); int prices[] = { 20, 30, 40, 50, 60, 70, 80, 90, 100 }; constraint(inside(price(), prices)); constraint(if_then(car() == MERCEDES, price() >= 40)); constraint(if_then(color() == RED, price() <= 40)); }