Exemplo n.º 1
0
        /// <summary>
        /// Simple constructor that initializes the data structures for keeping track of the state of each slave.
        /// The constructor receives two parameters: a boolean flag indicating whether the system should display
        /// information that is useful for debugging, and the maximum load per slave (the maximum number of jobs
        /// that a slave can be entrusted with at each time).
        /// </summary>
        public SlaveMonitor(IEvolutionState state, bool showDebugInfo, IMasterProblem problemPrototype)
        {
            ShowDebugInfo    = showDebugInfo;
            State            = state;
            ProblemPrototype = problemPrototype;

            var port = state.Parameters.GetInt(new Parameter(P_EVALMASTERPORT), null);

            MaxJobsPerSlave = state.Parameters.GetInt(new Parameter(P_MAXIMUMNUMBEROFCONCURRENTJOBSPERSLAVE), null);

            UseCompression = state.Parameters.GetBoolean(new Parameter(P_EVALCOMPRESSION), null, false);

            try
            {
                var tempTcpListener = new TcpListener(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0], port);
                tempTcpListener.Start();
                ServSock = tempTcpListener;
            }
            catch (IOException e)
            {
                state.Output.Fatal("Unable to bind to port " + port + ": " + e);
            }

            RandomSeed = (int)DateTimeHelper.CurrentTimeMilliseconds;

            // spawn the thread
            Thread = new ThreadClass(new AnonymousClassRunnable(state, this, problemPrototype).Run);
            Thread.Start();
        }
Exemplo n.º 2
0
        public virtual void Setup(IEvolutionState state, IParameter paramBase)
        {
            // Load my problem
            p_problem = (IProblem)(state.Parameters.GetInstanceForParameter(paramBase.Push(P_PROBLEM), null, typeof(IProblem)));
            p_problem.Setup(state, paramBase.Push(P_PROBLEM));

            // Am I a master problem and NOT a slave.  Note that the "eval.i-am-slave" parameter
            // is not set by the user but rather programmatically by the Slave class
            if (state.Parameters.ParameterExists(paramBase.Push(P_MASTERPROBLEM), null))
            // there's a master problem to load
            {
                // load the masterproblem so it can be accessed by the Slave as well (even though it's not used in its official capacity)
                MasterProblem = (IMasterProblem)(state.Parameters.GetInstanceForParameter(
                                                     paramBase.Push(P_MASTERPROBLEM), null, typeof(IProblem)));
                MasterProblem.Setup(state, paramBase.Push(P_MASTERPROBLEM));

                if (!state.Parameters.GetBoolean(paramBase.Push(P_IAMSLAVE), null, false))
                // I am a master (or possibly a slave -- same params)
                {
                    //try
                    //{
                    //    var masterproblem = (IProblem)(state.Parameters.GetInstanceForParameter(
                    //        paramBase.Push(P_MASTERPROBLEM), null, typeof(IProblem)));
                    //    masterproblem.Setup(state, paramBase.Push(P_MASTERPROBLEM));

                    /*
                     * If a MasterProblem was specified, interpose it between the
                     * evaluator and the real problem.  This allows seamless use
                     * of the master problem.
                     */
                    MasterProblem.Problem = p_problem;
                    p_problem             = MasterProblem;
                    //}
                    //catch (ParamClassLoadException)
                    //{
                    //    state.Output.Fatal("Parameter has an invalid value: " + paramBase.Push(P_MASTERPROBLEM));
                    //}
                }
            }
        }
Exemplo n.º 3
0
 private void  InitBlock(IEvolutionState state, ISlaveMonitor enclosingInstance, IMasterProblem problemPrototype)
 {
     _state             = state;
     _enclosingInstance = enclosingInstance;
     _problemPrototype  = problemPrototype;
 }
Exemplo n.º 4
0
 public AnonymousClassRunnable(IEvolutionState state, ISlaveMonitor enclosingInstance, IMasterProblem problemPrototype)
 {
     InitBlock(state, enclosingInstance, problemPrototype);
 }