Beispiel #1
0
 item(rand_obj* parent = 0)
     : rand_obj(parent), src_addr(this), dest_addr(this), data(this), x(this), y(this), z(this) {
   constraint(dist(src_addr(), distribution<uint>::simple_range(0, 0xFE)));
   constraint(dest_addr() <= src_addr());
   constraint("neg_data", -16 < data() && data() < 0);
   constraint("pos_data", 16 > data() && data() > 0);
   constraint(bitslice(10, 3, x()) == 0xFF);
   constraint(x() > 123456);
   constraint((y() ^ 0x7FFF) == 0);
   constraint((z() >> 4) == 0x000F);
 }
Beispiel #2
0
  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));
 }
Beispiel #4
0
 item(rand_obj* parent = 0) : rand_obj(parent), src_addr(this), dest_addr(this) {
   constraint(dist(src_addr(), distribution<unsigned>::create(range<unsigned>(0, 9))(range<unsigned>(90, 99))));
   constraint(dist(dest_addr(), distribution<unsigned>::create(weighted_range<unsigned>(0, 9, 60))(
                                    weighted_range<unsigned>(10, 19, 30))(weighted_range<unsigned>(100, 109, 10))));
 }
Beispiel #5
0
using crave::crv_object_name;

using crave::reference;
using crave::distribution;
using crave::dist;
using crave::bitslice;

class item : public crv_sequence_item {
 public:
  crv_variable<unsigned> src_addr;
  crv_variable<unsigned> dest_addr;
  crv_variable<short> data;
  crv_variable<int> x;
  crv_variable<short> y, z;

  crv_constraint c_addr_constraints{ dist(src_addr(), distribution<unsigned>::simple_range(0, 0xFE)),
                                     dest_addr() <= src_addr() };
  crv_constraint c_neg_data{ -16 < data(), data() < 0 };
  crv_constraint c_pos_data{ 16 > data(), data() > 0 };
  crv_constraint c_x_constraints{ bitslice(10, 3, x()) == 0xFF, x() > 123456 };
  crv_constraint c_y_constraints{(y() ^ 0x7FFF) == 0 };
  crv_constraint c_z_constraints{(z() >> 4) == 0x000F };

  item(crv_object_name) {}

  friend ostream& operator<<(ostream& os, item& it) {
    os << it.src_addr << " " << it.dest_addr << " " << it.data << " " << it.x << " " << it.y << " " << it.z;
    return os;
  }
};
Beispiel #6
0
	item(rand_obj* parent = 0) : rand_obj(parent), src_addr(this), dest_addr(this), data(this) {
		src_addr.range(0, 0xFE);
		constraint(dest_addr() <= reference(src_addr));
		constraint("neg_data", -10 < data() && data() < 0 );
		constraint("pos_data", 10 > data() && data() > 0);
	}