Expression getAdditional(Session session, Comparison other) {
   Expression add = other.getIfEquals(this.left);
   if ((add != null) && (add.isConstant())) {
     this.valueList.add(add);
     this.valueSet.add(add.getValue(session).convertTo(this.left.getType()));
     return this;
   }
   return null;
 }
Example #2
0
 @Override
 public Expression optimize(Session session) {
   left = left.optimize(session);
   boolean constant = left.isConstant();
   if (constant && left == ValueExpression.getNull()) {
     return left;
   }
   boolean allValuesConstant = true;
   boolean allValuesNull = true;
   int size = valueList.size();
   for (int i = 0; i < size; i++) {
     Expression e = valueList.get(i);
     e = e.optimize(session);
     if (e.isConstant() && e.getValue(session) != ValueNull.INSTANCE) {
       allValuesNull = false;
     }
     if (allValuesConstant && !e.isConstant()) {
       allValuesConstant = false;
     }
     if (left instanceof ExpressionColumn && e instanceof Parameter) {
       ((Parameter) e).setColumn(((ExpressionColumn) left).getColumn());
     }
     valueList.set(i, e);
   }
   if (constant && allValuesConstant) {
     return ValueExpression.get(getValue(session));
   }
   if (size == 1) {
     Expression right = valueList.get(0);
     Expression expr = new Comparison(session, Comparison.EQUAL, left, right);
     expr = expr.optimize(session);
     return expr;
   }
   if (allValuesConstant && !allValuesNull) {
     int leftType = left.getType();
     if (leftType == Value.UNKNOWN) {
       return this;
     }
     Expression expr = new ConditionInConstantSet(session, left, valueList);
     expr = expr.optimize(session);
     return expr;
   }
   return this;
 }
Example #3
0
 public Expression optimize(Session session) {
   boolean allConst = isDeterministic();
   for (int i = 0, len = args.length; i < len; i++) {
     Expression e = args[i].optimize(session);
     args[i] = e;
     allConst &= e.isConstant();
   }
   if (allConst) {
     return ValueExpression.get(getValue(session));
   }
   return this;
 }
 @Override
 public Expression optimize(Session session) {
   boolean allConst = true;
   for (int i = 0; i < list.length; i++) {
     Expression e = list[i].optimize(session);
     if (!e.isConstant()) {
       allConst = false;
     }
     list[i] = e;
   }
   if (allConst) {
     return ValueExpression.get(getValue(session));
   }
   return this;
 }
Example #5
0
  _FUNCTION_ZEROS(OptimizationProblem model, Expression a) {
    super(model);

    /* compute size */
    if (a.getNumDim() != 2)
      throw new JOMException(
          "Function 'zeros': Zeros function should receive a row or column vector of constants indicanting the array size");
    if ((a.getSize()[0] != 1) && (a.getSize()[1] != 1))
      throw new JOMException(
          "Function 'zeros': Zeros function should receive a row or column vector of constants indicanting the array size");
    if (!a.isConstant())
      throw new JOMException(
          "Function 'zeros': Zeros function should receive a row or column vector of constants indicanting the array size");

    double[] size_d = a.evaluateConstant().to1DArray();
    int[] size_i = new int[size_d.length];
    for (int cont = 0; cont < size_i.length; cont++) size_i[cont] = (int) size_d[cont];

    this.resize(size_i);
    this.affineExp = a.getAffineExpression().function_onesOrZeros(0);
  }