📄 t_deoptimizer.java
字号:
/*-----Deal with strategy first------------------*/
String S[] = deScreen.getStrategyIdentifiers();
Strategem = new DEStrategy [S.length];
for (i = 0; i < S.length; i++)
{
try
{ //give the full pathname here so the class can be located
Class C = Class.forName ("DeApp1.de.DE" + S[i]);
//System.out.println("Class"+ C);//Debug
Strategem[i] = (DEStrategy)C.newInstance();
Strategem[i].init (deRandom);
}
catch (Exception e)
{
System.err.println (e); // Fix
};
}
System.out.println("Strategies chosen\n");
/*-----Now care about the problem-----------------*/
String Identifier[] = deScreen.getProblemIdentifiers(); //list of problems
deProblemArray = new DEProblem[Identifier.length]; // Array of problem objects
//System.out.println("o.k.\n");
for (i = 0; i < Identifier.length; i++)
{//create an object for all problems possible -> improve that!
try
{//Give full path name here so the class can be found
Class C = Class.forName ("DeApp1.problem." + Identifier[i]);
//System.out.println(C);
deProblemArray[i] = (DEProblem)C.newInstance(); //select the problem
//deProblemArray[i].init (); //set initial size and some constants
}
catch (Exception e)
{
System.err.println (e);
System.out.println("i="+i);
};
}
if (action == null) //if thread is not running
{
action = new Thread (this); // Instantiate the new thread
action.start(); // Start it
}
}
public void stop ()
/***********************************************************
** Stop the thread when you leave the application. **
***********************************************************/
{
action = null;
}
public void run ()
/***********************************************************
** The "main()" method for the thread. **
***********************************************************/
// Let it run! The optimization is taking place here!
{
while (action != null) //as long as there is an active thread
{
/*--If we want the thread to pause we suspend the optimization.---*/
/*--We need this to be able to steer the optimization with--------*/
/*--the GUI buttons. Otherwise the optimization runs and runs...--*/
/*--Resuming of the thread activity via action.resume() is done---*/
/*--by means of the appropriate GUI event.------------------------*/
if (running == false)
{
action.suspend();
}
/*--Let the optimization sleep for the time NAPTIME so that the--*/
/*--observers get some time to show their graphics.--------------*/
/*--If we don't do this the human eye often can't follow the-----*/
/*--update of the console or the graphics.-----------------------*/
try
{
action.sleep (DEProblem.NAPTIME); // Suspend optimization for NAPTIME
}
catch (Exception E)
{
System.err.println (E); // In case the sleep command fails
};
/*--Run the optimizer Refresh times---------------*/
optimize(deProblemArray[current_problem]);
/*--update all observers (data panel,plot screens)---*/
deScreen.repaint();
/*--Give the new mincost to the problem. It's-----*/
/*--function completed() then decides whether-----*/
/*--to stop.--------------------------------------*/
deProblemArray[current_problem].mincost = mincost;
/*--Check if the VTR has been reached and the optimization--*/
/*--is completed.-------------------------------------------*/
if (deProblemArray[current_problem].completed())
{
makeNotReady(); // running = false, pause the thread
deScreen.done();
}
}
}
public synchronized void makeReady ()
/***********************************************************
** As the name says: Make the thread ready for running. **
***********************************************************/
{
running = true;
}
public synchronized void makeNotReady ()
/***********************************************************
** Prepare the thread for sleep. **
***********************************************************/
{
running = false;
}
// Some helper methods
public void setProblem (int index)
/***********************************************************
** Select the cost function. **
***********************************************************/
{
current_problem = index;
}
public void optIdle ()
/***********************************************************
** Suspend the animation. **
***********************************************************/
{
makeNotReady(); // Suspend the optimization
}
public void optStart ()
/***********************************************************
** Start the animation. **
***********************************************************/
{
generation = 0; // Initialize
evaluation = 0; // dto.
mincost = Double.MAX_VALUE; // dto.
deScreen.getParameters(); // get all the parameters from the panels
makeReady(); // Wake up the animation
action.resume(); // and get it going
}
public void optResume ()
/***********************************************************
** Wake the sleeping animation. **
***********************************************************/
{
deScreen.getParameters(); // get all the parameters from the panels
makeReady(); // Wake the animation up
action.resume(); // and get it going
}
/*====Some methods for the observers to get their input.=====*/
public int getGeneration ()
/***********************************************************
** Which iteration of the optimization ? **
***********************************************************/
{
return generation;
}
public int getEvaluation ()
/***********************************************************
** How many evaluations have been done so far ? **
***********************************************************/
{
return evaluation;
}
public double getMinimum ()
/***********************************************************
** What's the best cost value so far ? **
***********************************************************/
{
return mincost;
}
public final double[] getBest ()
/**********************************
** Best vector. **
**********************************/
{
return best;
}
/*====End of the observer methods.========================*/
public void consoleEnable()
/***********************************************************
** Enable console output trace of optimization parameters.**
***********************************************************/
{
console_out = true;
}
public void consoleDisable()
/***********************************************************
** Enable console output trace of optimization parameters.**
***********************************************************/
{
console_out = false;
}
public void updateTrialVector(double x[], int dim)
/***********************************************************
** Allows to updat the trial vector from outside. **
***********************************************************/
{
int i;
for (i=0; i<dim; i++)
{
trial[i] = x[i];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -