parameters: (self, expr)
docstring: Handles an expression that needs to be represented by an
          intermediate variable. Mainly for stuff under a weighted sum.
docstring_summary: Handles an expression that needs to be represented by an
          intermediate variable. Mainly for stuff under a weighted sum.
docstring_tokens: Handles an expression that needs to be represented by an intermediate variable . Mainly for stuff under a weighted sum .
function: def handle_extra_expression(self, expr):
          """
          Handles an expression that needs to be represented by an
          intermediate variable. Mainly for stuff under a weighted sum.
          """
          if type(expr) == int:
              return expr
          elif expr.is_var():
              return (expr.ident, expr.get_domain_tuple()[0], expr.get_domain_tuple()[1])
          elif expr.get_operator() == "Sum":
              self.handle_weighted_sum(expr)
          elif self.global_map.get(expr.get_operator()) != None:
              self.handle_global_constraint(expr)
          else:
              #if expr.get_children()[0].is_var():
              #    var = expr.get_children()[0]
              #else:
              #    var = self.handle_extra_expression(expr)
  
              # Create a variable
              v_lb, v_ub, domain = expr.get_children()[0].get_domain_tuple()
              coef = expr.get_children()[1]
              lb = min(v_lb * coef, v_ub * coef)
              ub = max(v_lb * coef, v_ub * coef)
              var_idx = self.create_variable(lb, ub)
  
              # Create a predicate
              function = self.get_expr(expr)
              params   = self.get_params(expr)
  
              dparams = []
              for par in params:
                  if par[0] == "VAR":
                      if par[1] not in dparams:
                          dparams.append(par[1])
  
              arity = len(dparams)
              scope = "V" + " V".join([str(i) for i in sorted(dparams)])
  
              if arity > self.__maxConstraintArity:
                  self.__maxConstraintArity = 2
  
              if self.pred_map.get(function) is None:
                  pred_idx = self.__local_pred_idx
                  self.__local_pred_idx += 1
                  pred_string = "\n\t<predicate name=\"P%d\">\n" % pred_idx
                  pred_string += "\n\t\t<parameters>\n"
                  pred_string += "\t\t\t\t%s\n" % params
                  pred_string += "\t\t</parameters>\n"
  
                  pred_string += "\n\t\t<expression>\n"
                  pred_string += "\t\t\t<functional>\n"
                  pred_string += "\t\t\t\t%s\n" % function
                  pred_string += "\t\t\t</functional>\n"
                  pred_string += "\t\t</expression>\n"
                  pred_string += "\t</predicate>\n"
  
                  # Create a constraint
                  self.__predicates.append(pred_string)
                  self.pred_map[function] = (pred_string, pred_idx)
  
              else:
                  pred_idx = self.pred_map.get(function)[1]
  
              con_string = "\n\t<constraint name=\"C%d\"" % self.__local_con_idx
              con_string += " arity=\"%d\" scope=\"%s\" reference=\"P%d\">\n" % (
                  arity,
                  scope,
                  pred_idx
              )
              self.__local_con_idx += 1
  
              con_string += "\t\t<parameters>\n"
              con_string += "\t\t\t" + scope + " %d" % coef + "\n"
              con_string += "\t\t</parameters>\n"
              con_string += "\t</constraint>\n"
  
              self.__constraints.append(con_string)
              return (var_idx, lb, ub)
function_tokens: def handle_extra_expression ( self , expr ) : if type ( expr ) == int : return expr elif expr . is_var ( ) : return ( expr . ident , expr . get_domain_tuple ( ) [ 0 ] , expr . get_domain_tuple ( ) [ 1 ] ) elif expr . get_operator ( ) == "Sum" : self . handle_weighted_sum ( expr ) elif self . global_map . get ( expr . get_operator ( ) ) != None : self . handle_global_constraint ( expr ) else : #if expr.get_children()[0].is_var(): #    var = expr.get_children()[0] #else: #    var = self.handle_extra_expression(expr) # Create a variable v_lb , v_ub , domain = expr . get_children ( ) [ 0 ] . get_domain_tuple ( ) coef = expr . get_children ( ) [ 1 ] lb = min ( v_lb * coef , v_ub * coef ) ub = max ( v_lb * coef , v_ub * coef ) var_idx = self . create_variable ( lb , ub ) # Create a predicate function = self . get_expr ( expr ) params = self . get_params ( expr ) dparams = [ ] for par in params : if par [ 0 ] == "VAR" : if par [ 1 ] not in dparams : dparams . append ( par [ 1 ] ) arity = len ( dparams ) scope = "V" + " V" . join ( [ str ( i ) for i in sorted ( dparams ) ] ) if arity > self . __maxConstraintArity : self . __maxConstraintArity = 2 if self . pred_map . get ( function ) is None : pred_idx = self . __local_pred_idx self . __local_pred_idx += 1 pred_string = "\n\t<predicate name=\"P%d\">\n" % pred_idx pred_string += "\n\t\t<parameters>\n" pred_string += "\t\t\t\t%s\n" % params pred_string += "\t\t</parameters>\n" pred_string += "\n\t\t<expression>\n" pred_string += "\t\t\t<functional>\n" pred_string += "\t\t\t\t%s\n" % function pred_string += "\t\t\t</functional>\n" pred_string += "\t\t</expression>\n" pred_string += "\t</predicate>\n" # Create a constraint self . __predicates . append ( pred_string ) self . pred_map [ function ] = ( pred_string , pred_idx ) else : pred_idx = self . pred_map . get ( function ) [ 1 ] con_string = "\n\t<constraint name=\"C%d\"" % self . __local_con_idx con_string += " arity=\"%d\" scope=\"%s\" reference=\"P%d\">\n" % ( arity , scope , pred_idx ) self . __local_con_idx += 1 con_string += "\t\t<parameters>\n" con_string += "\t\t\t" + scope + " %d" % coef + "\n" con_string += "\t\t</parameters>\n" con_string += "\t</constraint>\n" self . __constraints . append ( con_string ) return ( var_idx , lb , ub )