Class Converter
java.lang.Object
com.adriangarcia.metaheuristics.tsmbfoa.Converter
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected String[]
extendConstraintsValuate
(String constraintsValuate) Method that punctuates the constraints.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.extendRankVariables
(String rankVar) Sets the variable ranges.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.
-
Constructor Details
-
Converter
public Converter()
-
-
Method Details
-
extendFunction
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
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
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
Method that punctuates the constraints.- Parameters:
constraintsValuate
- constraints- Returns:
- constraints ordered
-