Esempio n. 1
0
  public void buildCompleteWE() {
    StringBuffer b = new StringBuffer("(");
    String patter = "((2(0|1))|((0|1)2))";
    int nd = 2;
    int nw = 4;
    int sd = 6;

    for (int w = 0; w < nw; w++) {
      b.append("(");
      for (int i = 1; i < sd + (7 * w); i++) b.append(all);
      b.append(patter);
      for (int i = (sd + 7 * w) + nd; i <= 28; i++) b.append(all);
      b.append(")|");
    }
    b.deleteCharAt(b.length() - 1).append(")");

    full =
        full.intersection(
            new RegExp(StringUtils.toCharExp(b.toString())).toAutomaton().complement());
    full.minimize();
  }
Esempio n. 2
0
  @Test
  public void exp2DTest() {

    // The data
    int dim = 2;
    int[][] domOrigins = {
      {0, 5, 0, 3},
      {0, 5, 0, 5},
      {0, 6, 0, 4},
      {0, 6, 0, 5},
      {0, 5, 0, 5},
      {0, 7, 0, 4},
      {0, 6, 0, 5},
      {0, 6, 0, 5},
      {0, 5, 0, 6},
      {0, 7, 0, 5}
    };

    int[][] shBoxes = {
      {0, 0, 0, 2, 3},
      {0, 1, 2, 2, 2},
      {1, 0, 0, 3, 2},
      {2, 0, 0, 2, 3},
      {3, 0, 0, 2, 2},
      {4, 0, 0, 3, 1},
      {4, 1, 0, 1, 2},
      {5, 0, 0, 1, 3},
      {6, 0, 0, 1, 2},
      {6, 0, 1, 2, 1},
      {7, 0, 0, 2, 1},
      {7, 1, 0, 1, 2},
      {8, 0, 0, 3, 1},
      {9, 0, 0, 1, 2}
    };
    int[] v0 = {-1, -2, -3};
    int[] v1 = {-1, 2, 3};
    int[] v2 = {-1, 2, -3};
    int[] v3 = {-1, 3, -2};

    int nbOfObj = 10;

    // create the choco problem
    Model m = new CPModel();

    // Create Objects
    List<GeostObject> obj = new ArrayList<GeostObject>();

    for (int i = 0; i < nbOfObj; i++) {
      IntegerVariable shapeId = makeIntVar("sid", i, i);
      IntegerVariable coords[] = new IntegerVariable[dim];
      coords[0] = makeIntVar("x", domOrigins[i][0], domOrigins[i][1]);
      coords[1] = makeIntVar("y", domOrigins[i][2], domOrigins[i][3]);

      IntegerVariable start = makeIntVar("start", 1, 1);
      IntegerVariable duration = makeIntVar("duration", 1, 1);
      IntegerVariable end = makeIntVar("end", 1, 1);
      obj.add(new GeostObject(dim, i, shapeId, coords, start, duration, end));
    }

    // create shiftedboxes and add them to corresponding shapes
    List<ShiftedBox> sb = new ArrayList<ShiftedBox>();
    for (int i = 0; i < shBoxes.length; i++) {
      int[] offset = {shBoxes[i][1], shBoxes[i][2]};
      int[] sizes = {shBoxes[i][3], shBoxes[i][4]};
      sb.add(new ShiftedBox(shBoxes[i][0], offset, sizes));
    }

    // Create the external constraints vecotr
    List<IExternalConstraint> ectr = new ArrayList<IExternalConstraint>();
    // create the list of dimensions for the external constraint
    int[] ectrDim = new int[dim];
    for (int d = 0; d < dim; d++) ectrDim[d] = d;

    // create the list of object ids for the external constraint
    int[] objOfEctr = new int[nbOfObj];
    for (int d = 0; d < nbOfObj; d++) {
      objOfEctr[d] = obj.get(d).getObjectId();
    }

    //		create the external constraint of type non overlapping
    NonOverlappingModel n = new NonOverlappingModel(Constants.NON_OVERLAPPING, ectrDim, objOfEctr);
    // add the external constraint to the vector
    ectr.add(n);

    // create the list of controlling vectors
    List<int[]> ctrlVs = new ArrayList<int[]>();
    ctrlVs.add(v0);
    // ctrlVs.add(v1);
    // ctrlVs.add(v2);
    // ctrlVs.add(v3);

    // create the geost constraint
    Constraint geost = geost(dim, obj, sb, ectr, ctrlVs);

    // NOTA: you can choose to not take into account of the greedy mode by creating the geost
    // constraint as follows:
    // Geost_Constraint geost = new Geost_Constraint(vars, dim, obj, sb, ectr);

    // post the geost constraint to the choco problem
    m.addConstraint(geost);

    Solver s = new CPSolver();
    s.read(m);

    // solve the probem
    s.solve();

    for (int i = 0; i < obj.size(); i++) {
      GeostObject o = obj.get(i);
      StringBuffer st = new StringBuffer();
      st.append(MessageFormat.format("Object {0}: ", o.getObjectId()));
      for (int j = 0; j < dim; j++)
        st.append(MessageFormat.format("{0} ", s.getVar(o.getCoordinates()[j])));
      LOGGER.info(st.toString());
    }
  }