Пример #1
0
    @Override
    public void invoke(IObject instance, IObject... expressions) {
      IConstraintNetwork network = solver.getConstraintNetwork();
      instance.set(CAPACITY, expressions[0]);
      INumber initial_amount = network.newReal();
      instance.set(INITIAL_AMOUNT, initial_amount);
      INumber final_amount = network.newReal();
      instance.set(FINAL_AMOUNT, final_amount);
      solver
          .getCurrentNode()
          .addResolver(
              new IResolver() {
                private boolean resolved = false;

                @Override
                public double getKnownCost() {
                  return 0;
                }

                @Override
                public void resolve() {
                  assert !resolved;
                  network.assertFacts(
                      network.geq(initial_amount, network.newReal("0")),
                      network.leq(initial_amount, (INumber) expressions[0]),
                      network.geq(final_amount, network.newReal("0")),
                      network.leq(final_amount, (INumber) expressions[0]));
                  resolved = true;
                }

                @Override
                public boolean isResolved() {
                  return resolved;
                }

                @Override
                public void retract() {
                  assert resolved;
                  resolved = false;
                }
              });
    }