예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:GAF.Network.NetworkWrapper"/> class.
        /// </summary>
        /// <param name="geneticAlgorithm">Genetic algorithm.</param>
        /// <param name="serviceDiscoveryClient">Service discovery client.</param>
        /// <param name="fitnessAssemblyName">Fitness assembly name.</param>
        /// <param name="reInitialise">If set to <c>true</c> to re-initialise the server.</param>
        /// <remarks>
        /// Re-initialising the server will, if the fitness function is not defined by the server,
        /// re-transmit the the fitness function to the server.
        /// </remarks>
        public NetworkWrapper(GAF.GeneticAlgorithm geneticAlgorithm, IServiceDiscovery serviceDiscoveryClient, string fitnessAssemblyName, bool initialise)
        {
            if (geneticAlgorithm == null)
            {
                throw new ArgumentNullException(nameof(geneticAlgorithm));
            }

            if (geneticAlgorithm.Population == null)
            {
                throw new NullReferenceException("The specified GeneticAlgorithm.Population object is null.");
            }

            if (geneticAlgorithm.Population.Solutions == null || geneticAlgorithm.Population.Solutions.Count == 0)
            {
                throw new NullReferenceException("The specified GeneticAlgorithm.PopulationSolutions object is null or empty.");
            }

            if (serviceDiscoveryClient == null)
            {
                throw new NullReferenceException("The specified IServiceDiscovery object is null");
            }

            if (string.IsNullOrEmpty(fitnessAssemblyName))
            {
                throw new NullReferenceException("The specified fitness assembly name is null or empty");
            }
            _serviceDiscoveryClient = serviceDiscoveryClient;
            _fitnessAssemblyName    = fitnessAssemblyName;

            //store the referenc to the GA and hook up to the evaluation begin class
            this.GeneticAlgorithm = geneticAlgorithm;
            this.GeneticAlgorithm.Population.OnEvaluationBegin += OnEvaluationBegin;

            //get the endpoints from consul
            Log.Info("Getting remote endpoints from Service Discovery.");
            this.EndPoints = _serviceDiscoveryClient.GetActiveServices(ServiceName);

            if (this.EndPoints.Count == 0)
            {
                throw new ServiceDiscoveryException("No server endpoints detected. Check that servers are running and registered with the appropriate IServiceDiscovery service.");
            }

            LogEndpoints(EndPoints);

            _evaluationClient = new EvaluationClient(this.EndPoints, _fitnessAssemblyName);
        }
예제 #2
0
 /// <summary>
 /// Gets the active services.
 /// </summary>
 /// <returns>The active services.</returns>
 /// <param name="serviceName">Service name.</param>
 public List <IPEndPoint> GetActiveServices(string serviceName)
 {
     return(_serviceDiscovery.GetActiveServices(serviceName));
 }