Example #1
0
 private static void readAnnotations(
     String name,
     Declaration type,
     List<EAnnotation> expressions,
     FZNLayout layout,
     THashMap<String, Object> map) {
   for (int i = 0; i < expressions.size(); i++) {
     Expression expression = expressions.get(i);
     Expression.EType etype = expression.getTypeOf();
     Annotation varanno = Annotation.none;
     switch (etype) {
       case IDE:
         EIdentifier identifier = (EIdentifier) expression;
         varanno = Annotation.valueOf((identifier).value);
         break;
       case ANN:
         EAnnotation eanno = (EAnnotation) expression;
         varanno = Annotation.valueOf(eanno.id.value);
         break;
       default:
         //                    LOGGER.warn("% Unknown annotation :" + type.toString());
     }
     switch (varanno) {
       case output_var:
         IntVar var = (IntVar) map.get(name);
         layout.addOutputVar(name, var, type);
         break;
       case output_array:
         EAnnotation eanno = (EAnnotation) expression;
         IntVar[] vars = (IntVar[]) map.get(name);
         layout.addOutputArrays(name, vars, eanno.exps, type);
         break;
       default:
         // LOGGER.warn("% Unknown annotation :" + varanno.toString());
     }
     break;
   }
 }
Example #2
0
 private static IntVar buildOnExpression(
     String name, Expression expression, THashMap<String, Object> map, Solver solver) {
   final IntVar iv;
   switch (expression.getTypeOf()) {
     case BOO:
       iv = expression.boolVarValue(solver);
       break;
     case INT:
       iv = VariableFactory.fixed(name, expression.intValue(), solver);
       break;
     case IDE:
       iv = VariableFactory.eq((IntVar) map.get(expression.toString()));
       break;
     case IDA:
       EIdArray eida = (EIdArray) expression;
       iv = ((IntVar[]) map.get(eida.name))[eida.index - 1];
       break;
     default:
       iv = null;
       Exit.log("Unknown expression");
   }
   return iv;
 }
Example #3
0
 /**
  * Build an array of <? extends {@link solver.variables.Variable}>. </br>WARNING: array's indice
  * are from 1 to n.
  *
  * @param name name of the array of variables.</br> Each variable is named like {@code name}_i.
  * @param type {@link parser.flatzinc.ast.declaration.DArray} object.
  * @param map
  * @param solver
  */
 private static void buildWithDArray(
     String name,
     DArray type,
     Expression expression,
     THashMap<String, Object> map,
     Solver solver) {
   final DInt2 index = (DInt2) type.getIndex(0);
   // no need to get lowB, it is always 1 (see specification of FZN for more informations)
   final int size = index.getUpp();
   final Declaration what = type.getWhat();
   final IntVar[] vs;
   switch (what.typeOf) {
     case BOOL:
       BoolVar[] bs = new BoolVar[size];
       if (expression == null) {
         for (int i = 1; i <= size; i++) {
           bs[i - 1] = buildWithBool(name + '_' + i, expression, map, solver);
         }
       } else if (expression.getTypeOf().equals(Expression.EType.ARR)) {
         EArray array = (EArray) expression;
         // build the array
         for (int i = 0; i < size; i++) {
           bs[i] = array.getWhat_i(i).boolVarValue(solver);
         }
       }
       map.put(name, bs);
       break;
     case INT:
       vs = new IntVar[size];
       if (expression == null) {
         for (int i = 1; i <= size; i++) {
           vs[i - 1] = buildWithInt(name + '_' + i, null, map, solver);
         }
       } else if (expression.getTypeOf().equals(Expression.EType.ARR)) {
         buildFromIntArray(vs, (EArray) expression, size, solver);
       }
       map.put(name, vs);
       break;
     case INT2:
       vs = new IntVar[size];
       if (expression == null) {
         for (int i = 1; i <= size; i++) {
           vs[i - 1] = buildWithInt2(name + '_' + i, (DInt2) what, expression, map, solver);
         }
       } else if (expression.getTypeOf().equals(Expression.EType.ARR)) {
         buildFromIntArray(vs, (EArray) expression, size, solver);
       }
       map.put(name, vs);
       break;
     case INTN:
       vs = new IntVar[size];
       if (expression == null) {
         for (int i = 1; i <= size; i++) {
           vs[i - 1] = buildWithManyInt(name + '_' + i, (DManyInt) what, expression, map, solver);
         }
       } else if (expression.getTypeOf().equals(Expression.EType.ARR)) {
         buildFromIntArray(vs, (EArray) expression, size, solver);
       }
       map.put(name, vs);
       break;
     case SET:
       //                final SetVariable[] svs = new SetVariable[size];
       //                for (int i = 1; i <= size; i++) {
       //                    svs[i - 1] = buildWithSet(name + '_' + i, (DSet) what, map);
       //                }
       //                map.put(name, svs);
       Exit.log("SET VAR");
       break;
     default:
       break;
   }
 }