Class Converter

java.lang.Object
com.adriangarcia.metaheuristics.tsmbfoa.Converter

public class Converter extends Object
To optimize a CNOP it is necessary to make constant evaluations of its mathematical expressions. However, they are never the same or of the same type. For them this class is in charge of preparing the CNOP input so that the expression evaluator is in charge of evaluating and substituting the exact values.
Version:
1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String[]
    extendConstraintsValuate(String constraintsValuate)
    Method that punctuates the constraints.
    This method takes care of obtaining a summarized mathematical expression and extends it, very common in the case of summations and products.Extends a function introduced by string, e.g:

    if the entry expression is
    5 * sum{x,1,4,xi} - prod{x,1,4,(xi+i)}

    conversion will return
    5 * (x1+x2+x3+x4) - ((x1+1)*(x2+2)*(x3+3)*(x4+4))

    the purpose is that mXparse is in charge of evaluating and substituting directly the values for each variable.
    Sets the variable ranges.
    This method is in charge of punctuating the number of variable that the CNOP contains, to give it a value at the moment of evaluation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Converter

      public Converter()
  • Method Details

    • extendFunction

      public String extendFunction(String function)
      This method takes care of obtaining a summarized mathematical expression and extends it, very common in the case of summations and products.Extends a function introduced by string, e.g:

      if the entry expression is
      5 * sum{x,1,4,xi} - prod{x,1,4,(xi+i)}

      conversion will return
      5 * (x1+x2+x3+x4) - ((x1+1)*(x2+2)*(x3+3)*(x4+4))

      the purpose is that mXparse is in charge of evaluating and substituting directly the values for each variable.
      allowed syntax:

      summation: sum{var, from, to, f(x1,x2,...,xn)}
      Product: prod{var, from, to, f(x1,x2,...,xn)}
      Parameters:
      function - a summarized mathematical expression
      Returns:
      an extended mathematical expression
    • extendVariables

      public String[] extendVariables(String varOrder)
      This method is in charge of punctuating the number of variable that the CNOP contains, to give it a value at the moment of evaluation. If the input of variables is extensive, iteration can be used, e.g:

      if the variables input is:
      p1; p2; iter{x,1,3}; iter{y,1,4}; p1; p2

      conversion will return
      [p1, p2, x1, x2, x3, y1, y2, y3, y4, p1, p2]

      all elements inside the iteration are separated by commas (,) and outside the iteration are separated by semicolons (;).
      Parameters:
      varOrder - variable expression
      Returns:
      vector of FO variables
    • extendRankVariables

      public String extendRankVariables(String rankVar)
      Sets the variable ranges. When there are many variables and a number of them have the same rank, the rank iteration can be used: for example if we have 10 variables and the first two are different ranks, the five consequent ones have the same value and the last three have a different rank, the following abbreviation can be used:

      (0,1.2);(0,1.8);ran{3:7,0:1.2};ran{8:10,0.25:2}

      conversion will return
      (0,1.2),(0,1.8),(0,1.2),(0,1.2),(0,1.2),(0,1.2),(0,1.2),(0.25,2),(0.25,2),(0.25,2)

      all elements within the iteration are separated by commas (,) and ranges by colons (:) and outside the iteration are separated by semicolons (;).
      Parameters:
      rankVar - expression of the range of variables to iterate
      Returns:
      Ranges for each variable
    • extendConstraintsValuate

      protected String[] extendConstraintsValuate(String constraintsValuate)
      Method that punctuates the constraints.
      Parameters:
      constraintsValuate - constraints
      Returns:
      constraints ordered