public class MGAGenCMu extends Object implements RunTimeLimit
Summary of the algorithm:
For non-negativity constraint: a variable with negative value is changed to 0.
To reduce the simulation time, the solutions are not simulated with less than the normal number of replications. Then only the good solution candidates are re-simulated with the normal number of replications.
This version implements the standard version of the cross entropy algorithm.
Modifier and Type | Class and Description |
---|---|
static class |
MGAGenCMu.Results |
Modifier and Type | Field and Description |
---|---|
protected MGAGenCMu.Results |
bestResults |
protected boolean[][] |
canServe |
protected CallCenter |
cc |
protected boolean |
ceSmoothing |
protected double |
ceSmoothingRatio
The smoothing ratio to be used when
ceSmoothing is set to true. |
protected boolean |
initLocalSearch
Set if the algorithm should be for local search around the current parameters.
|
protected double |
initLocalSearchStdRatio
If the parameter
initLocalSearch is true, then the initial
standard deviation of the distributions will be set as this proportion of the inputted means. |
protected int |
lastRunTimeSec |
protected boolean |
noNegativeParams |
double |
normalDistMinStd
Minimum standard deviation parameter when generating a normal random variable.
|
protected int |
numDimensions |
protected int |
numGroups |
protected double |
numNormalRatio |
protected int |
numTypes |
protected RoutingObjectiveFunc |
objFunc |
protected int |
optTimeLimitSec |
protected int[] |
paramsCount |
protected GenCMuRouting.GenCMuRouter |
router |
protected RandomStream |
rs |
protected CallCenterSim |
sim |
protected double |
simRepRatio |
Constructor and Description |
---|
MGAGenCMu(CallCenterSim sim,
RoutingObjectiveFunc objFunc) |
Modifier and Type | Method and Description |
---|---|
double[] |
convertMatrixToVector(double[][] x)
Convert the parameters from matrix form into a single vector.
|
double |
eval(double[] x) |
void |
exportSolution(String outputFn) |
protected double[] |
generateSolution(double[] mean,
double[] std)
Generate a solution from a normal distribution with the given mean and
standard deviation.
|
double[][] |
getBestFuncParams()
Get the parameters of the derivative functions of the best solution found.
|
MGAGenCMu.Results |
getBestResults() |
double |
getBestScore()
Get the score of the best solution found.
|
boolean |
getCrossEntropySmoothing()
Get the cross entropy smoothing parameter.
|
double |
getCrossEntropySmoothingRatio()
The smoothing ratio to be used when
ceSmoothing is set to true. |
double[][] |
getFuncParams(double[] x)
Convert the solution from vector to matrix where each row represents a function.
|
boolean |
getInitLocalSearch() |
int |
getLastRunTimeSec()
Get the run time in seconds of the last execution.
|
boolean |
getNoNegativeParams() |
double |
getNumNormalRatio()
Get the ratio (relative to the population to keep)
of number of solutions to simulate.
|
RandomStream |
getRandomStream()
Get the uniform random number generator that is used.
|
double |
getSimRepRatio()
Get the number of replications ratio between short and normal simulations.
|
int |
getTimeLimitSec()
Get the time limit in seconds.
|
static void |
main(String[] args) |
void |
optimize(int popSize,
int popKeep,
int maxIt,
int maxNoImprIt,
double tol)
Execute the cross entropy optimization.
|
void |
setCrossEntropySmoothing(boolean s)
Set the cross entropy update smoothing.
|
void |
setCrossEntropySmoothingRatio(double r)
The smoothing ratio to be used when
ceSmoothing is set to true. |
void |
setInitLocalSearch(boolean b) |
void |
setInitLocalSearchStdRatio(double r) |
void |
setNoNegativeParams(boolean b)
Choose to allow negative parameters or not.
|
void |
setNumNormalRatio(double r)
Control the number of short simulation solutions to be simulated with normal
number of replications.
|
void |
setRandomStream(RandomStream s)
Set the uniform random number generator to be used.
|
void |
setSimRepRatio(double r)
Control the size of the short simulations.
|
void |
setTimeLimitSec(int sec)
Set the time limit in seconds.
|
protected boolean |
updateBestResults(double[] x,
double score)
Internal method to update the bestResults if the score is lower than the current
best results.
|
public double normalDistMinStd
protected CallCenterSim sim
protected CallCenter cc
protected GenCMuRouting.GenCMuRouter router
protected RoutingObjectiveFunc objFunc
protected int numTypes
protected int numGroups
protected boolean[][] canServe
protected int numDimensions
protected int[] paramsCount
protected MGAGenCMu.Results bestResults
protected RandomStream rs
protected double simRepRatio
protected double numNormalRatio
protected boolean ceSmoothing
protected double ceSmoothingRatio
ceSmoothing
is set to true.
This value must be between 0 and 1. The mean and standard deviation of the current
elite population will have a weight of ceSmoothingRatio
and the past mean
and standard deviation will have a weight of 1 minus this value.protected int lastRunTimeSec
protected int optTimeLimitSec
protected boolean noNegativeParams
protected boolean initLocalSearch
initLocalSearchStdRatio
.protected double initLocalSearchStdRatio
initLocalSearch
is true, then the initial
standard deviation of the distributions will be set as this proportion of the inputted means.public MGAGenCMu(CallCenterSim sim, RoutingObjectiveFunc objFunc)
public void setNoNegativeParams(boolean b)
b
- public boolean getNoNegativeParams()
public void setRandomStream(RandomStream s)
s
- the uniform random number generator to be used.public RandomStream getRandomStream()
public void setSimRepRatio(double r)
r
- the number of replications ratio between short and normal simulations.public double getSimRepRatio()
public void setNumNormalRatio(double r)
r
- the ratio (relative to the population to keep)
of number of solutions to simulate.public double getNumNormalRatio()
public void setCrossEntropySmoothing(boolean s)
s
- set to use update smoothing.public boolean getCrossEntropySmoothing()
public void setCrossEntropySmoothingRatio(double r)
ceSmoothing
is set to true.
This value must be between 0 and 1. See setCrossEntropySmoothing(boolean)
.public double getCrossEntropySmoothingRatio()
ceSmoothing
is set to true.
This value must be between 0 and 1. See setCrossEntropySmoothing(boolean)
.public void setTimeLimitSec(int sec)
RunTimeLimit
setTimeLimitSec
in interface RunTimeLimit
sec
- the time limit in seconds.public int getTimeLimitSec()
RunTimeLimit
getTimeLimitSec
in interface RunTimeLimit
public int getLastRunTimeSec()
RunTimeLimit
getLastRunTimeSec
in interface RunTimeLimit
public void setInitLocalSearch(boolean b)
public boolean getInitLocalSearch()
public void setInitLocalSearchStdRatio(double r)
public void optimize(int popSize, int popKeep, int maxIt, int maxNoImprIt, double tol)
popSize
- the population size at each iteration.popKeep
- the number of solutions to keep in each iteration.maxIt
- the maximum number of iterations.maxNoImprIt
- stopping condition: the maximum number of consecutive iterations without improving
the quantile cost (cost of the costliest elite solution).tol
- the convergence threshold of the standard variation, the
algorithm stops when all the standard variations are below this level.protected double[] generateSolution(double[] mean, double[] std)
mean
- the mean of each variable.std
- the standard deviation of each variable.public double eval(double[] x)
protected boolean updateBestResults(double[] x, double score)
x
- the new solution.score
- the corresponding score value.public MGAGenCMu.Results getBestResults()
public double[][] getFuncParams(double[] x)
x
- solution in vector form.public double[] convertMatrixToVector(double[][] x)
x
- the parameters in matrix form.public double[][] getBestFuncParams()
public double getBestScore()
public void exportSolution(String outputFn)