示例#1
0
  private void modelPrOfElement() {

    store = new Store();
    vars = new ArrayList<IntVar>();

    int[] valS = {1, 2, 4};
    double[] minPS = {0.3, 0.2, 0.1};
    double[] maxPS = {0.7, 0.3, 0.5};
    IntVar[] PsS = new IntVar[valS.length];
    int res = 10;

    StochasticVar S = new StochasticVar(store, "S", valS, minPS, maxPS);
    for (int i = 0; i < valS.length; i++) PsS[i] = new IntVar(store, "PEl" + valS[i], 0, res);

    store.impose(new PrOfElement(S, valS, PsS, res));

    for (IntVar V : PsS) vars.add(V);

    store.impose(new Sum(PsS, new IntVar(store, "Res", res, res)));

    IntVar E = new IntVar(store, "Expectation", 0, S.dom().values[S.getSize() - 1] * res);
    vars.add(E);
    store.impose(new SumWeight(PsS, valS, E));

    System.out.println(store);
  }
示例#2
0
  private void modelElement() {

    store = new Store();
    vars = new ArrayList<IntVar>();
    int res = 10;

    int[] valS0 = {1, 2};
    double[] minPS0 = {0.5, 0.5};
    double[] maxPS0 = {0.5, 0.5};
    IntVar[] PsS0 = new IntVar[valS0.length];

    StochasticVar S0 = new StochasticVar(store, "S0", valS0, minPS0, maxPS0);
    for (int i = 0; i < valS0.length; i++) PsS0[i] = new IntVar(store, "PEl" + valS0[i], 0, res);

    store.impose(new PrOfElement(S0, valS0, PsS0, res));

    for (IntVar V : PsS0) vars.add(V);

    store.impose(new Sum(PsS0, new IntVar(store, "Res", res, res)));

    int[] valS1 = {2, 3};
    double[] minPS1 = {0.4, 0.6};
    double[] maxPS1 = {0.4, 0.6};
    IntVar[] PsS1 = new IntVar[valS1.length];

    StochasticVar S1 = new StochasticVar(store, "S1", valS1, minPS1, maxPS1);
    for (int i = 0; i < valS1.length; i++) PsS1[i] = new IntVar(store, "PEl" + valS1[i], 0, res);

    store.impose(new PrOfElement(S1, valS1, PsS1, res));

    for (IntVar V : PsS1) vars.add(V);

    store.impose(new Sum(PsS1, new IntVar(store, "Res", res, res)));

    StochasticVar[] list = {S0, S1};

    StochasticVar S = new StochasticVar(store, "S", list);
    int[] valS = S.dom().values;
    IntVar[] PsS = new IntVar[valS.length];

    for (int i = 0; i < valS.length; i++) PsS[i] = new IntVar(store, "PEl" + valS[i], 0, res);

    store.impose(new PrOfElement(S, valS, PsS, res));

    for (IntVar V : PsS) vars.add(V);

    store.impose(new Sum(PsS, new IntVar(store, "Res", res, res)));

    IntVar index = new IntVar(store, "index", 0, 1);
    vars.add(index);

    store.impose(new Element(index, list, S));
  }