ec.eval
Class MasterProblemServer

java.lang.Object
  extended by ec.eval.MasterProblemServer
All Implemented Interfaces:
IMasterProblemServer, java.io.Serializable, java.lang.Runnable

public class MasterProblemServer
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable, IMasterProblemServer

MasterProblemServer.java

The server awaits for incoming slaves to connect. Upon one such connection is established, the server creates and starts a worker thread to manage all the incoming communication from this slave.

Parameters

eval.master.port
int
(the port where the slaves will connect)
eval.compression
boolean
(whether the communication with the slaves should be compressed or not)
eval.masterproblem.max-jobs-per-slave
int
(the maximum load (number of jobs) per slave at any point in time)

Version:
1.0
Author:
Liviu Panait
See Also:
Serialized Form

Field Summary
 java.net.ServerSocket servSock
          The socket where slaves connect.
 SlaveMonitor slaveMonitor
           
 EvolutionState state
           
 boolean useCompression
          Indicates whether compression is used over the socket IO streams.
 
Fields inherited from interface ec.eval.IMasterProblemServer
P_EVALCOMPRESSION, P_EVALMASTERPORT, P_MAXIMUMACTIVESLAVES, P_MAXIMUMNUMBEROFCONCURRENTJOBSPERSLAVE
 
Constructor Summary
MasterProblemServer()
          zero-argument constructor for deserialization
MasterProblemServer(boolean showDebugInfo)
           
 
Method Summary
 boolean evaluatedIndividualAvailable()
           
 QueueIndividual getEvaluatedIndividual(EvolutionState state)
           
 int numAvailableSlaves()
          Returns the number of available slave (not busy)
 QueueIndividual pollNextEvaluatedIndividual(EvolutionState state, long timeoutInMilliseconds)
          Polls for the next evaluated individual.
 void run()
          The run method waits for incoming slaves, and launches new worker threads (one per incoming slave) to handle the communication with the slave.
 void scheduleJobForEvaluation(EvolutionState state, Job ed)
          Schedules a remote evaluation.
 void setJobSize(int jobSize)
          A hint as to the maximum number of jobs per slave task.
 void setupServerFromDatabase(EvolutionState state)
          After the MasterProblemServer is created, it needs to be told to initialize itself from information in the parameter database.
 void shutdown()
          Indicates that the background thread is to shut down and closes the server socket.
 java.lang.Thread spawnThread()
          Creates and starts a background thread for this server.
 void waitForAllSlavesToFinishEvaluating(EvolutionState state)
          Wait for remote evaluation to complete.
 Individual waitForIndividual(EvolutionState state)
          Wait for one individual to complete evaluation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

slaveMonitor

public SlaveMonitor slaveMonitor

servSock

public java.net.ServerSocket servSock
The socket where slaves connect.


useCompression

public boolean useCompression
Indicates whether compression is used over the socket IO streams.


state

public EvolutionState state
Constructor Detail

MasterProblemServer

public MasterProblemServer()
zero-argument constructor for deserialization


MasterProblemServer

public MasterProblemServer(boolean showDebugInfo)
Method Detail

setJobSize

public void setJobSize(int jobSize)
Description copied from interface: IMasterProblemServer
A hint as to the maximum number of jobs per slave task. The server is free to ignore or modify this value.

Specified by:
setJobSize in interface IMasterProblemServer

setupServerFromDatabase

public void setupServerFromDatabase(EvolutionState state)
After the MasterProblemServer is created, it needs to be told to initialize itself from information in the parameter database. It distinguishes between starting fresh and restoring from a checkpoint by the state of the randomStates and slaves arrays.

Specified by:
setupServerFromDatabase in interface IMasterProblemServer
Parameters:
state - the evolution state

shutdown

public void shutdown()
Indicates that the background thread is to shut down and closes the server socket. (should probably be synchronized).

Specified by:
shutdown in interface IMasterProblemServer

numAvailableSlaves

public int numAvailableSlaves()
Description copied from interface: IMasterProblemServer
Returns the number of available slave (not busy)

Specified by:
numAvailableSlaves in interface IMasterProblemServer

evaluatedIndividualAvailable

public boolean evaluatedIndividualAvailable()
Specified by:
evaluatedIndividualAvailable in interface IMasterProblemServer
Returns:
true if there are individuals that have completed evaluation but not yet been processed.

scheduleJobForEvaluation

public void scheduleJobForEvaluation(EvolutionState state,
                                     Job ed)
Description copied from interface: IMasterProblemServer
Schedules a remote evaluation.

Specified by:
scheduleJobForEvaluation in interface IMasterProblemServer
Parameters:
state - Evolution state
ed - Evaluation data for one individual or group

waitForAllSlavesToFinishEvaluating

public void waitForAllSlavesToFinishEvaluating(EvolutionState state)
Description copied from interface: IMasterProblemServer
Wait for remote evaluation to complete.

Specified by:
waitForAllSlavesToFinishEvaluating in interface IMasterProblemServer

waitForIndividual

public Individual waitForIndividual(EvolutionState state)
Description copied from interface: IMasterProblemServer
Wait for one individual to complete evaluation.

Specified by:
waitForIndividual in interface IMasterProblemServer

getEvaluatedIndividual

public QueueIndividual getEvaluatedIndividual(EvolutionState state)
Specified by:
getEvaluatedIndividual in interface IMasterProblemServer

pollNextEvaluatedIndividual

public QueueIndividual pollNextEvaluatedIndividual(EvolutionState state,
                                                   long timeoutInMilliseconds)
Description copied from interface: IMasterProblemServer
Polls for the next evaluated individual.

Specified by:
pollNextEvaluatedIndividual in interface IMasterProblemServer
timeoutInMilliseconds - Timeout for individual to be received
Returns:
QueueIndividual, or null if no individual is received before the timeout.

run

public void run()
The run method waits for incoming slaves, and launches new worker threads (one per incoming slave) to handle the communication with the slave.

Specified by:
run in interface java.lang.Runnable

spawnThread

public java.lang.Thread spawnThread()
Creates and starts a background thread for this server.

Specified by:
spawnThread in interface IMasterProblemServer
Returns:
the background thread