Example #1
0
        /// <summary>
        /// runs the optimizer
        /// </summary>
        public void run()
        {
            initializeStreams();
            // assign a batch id for the solution manager
            batchid = fetchBatchId();
            // assign a solution id generator for the manager
            gen = new SolutionIdGenerator("all_solutions", 100, DbApi());

            var task1 = startAllSolutionInsert();
            var task2 = startDeletedSolutionInsert();

            // run the agents and clean up
            for (int i = 0; i < 300; i++)
            {
                runAgents(createrAgents, allSolutionsStream);
            }

            for (int i = 0; i < 12; i++)
            {
                runAgents(workerAgents, allSolutionsStream);
                if (i != 0 && i % 3 == 0)
                {
                    runAgents(destroyerAgents, deletedSolutionsStream);
                }
            }
            cleanup();
            stopStreams();
            waitForThreads(task1, task2);
        }
Example #2
0
        /// <summary>
        /// Re runs the optimizer using the defined rules
        /// </summary>
        /// <param name="newRules">the list of new rules</param>
        /// <param name="batchId">the batchid of the solutions againast which this runs</param>
        public void rerun(List <Rule> newRules, int batchId)
        {
            this.batchid = batchId;
            // fetch solutions from database and add them to our population
            initializeStreams();
            this.population = getSolutionsForABatchId(batchId).Select(x =>
            {
                runAndEvaluateObjective(x);
                return(x);
            });
            //assign the solution id generator
            gen = new SolutionIdGenerator("all_solutions", 100, DbApi());
            createRulesAndDestroyerAgents(newRules); // create destroyer agents to incorporate rules
            var task1 = startAllSolutionInsert();
            var task2 = startDeletedSolutionInsert();

            for (int i = 0; i < 12; i++)
            {
                runAgents(workerAgents, allSolutionsStream);
                if (i != 0 && i % 3 == 0)
                {
                    runAgents(destroyerAgents, deletedSolutionsStream);
                }
            }
            // clean up
            cleanup();
            stopStreams();
            waitForThreads(task1, task2);
        }
Example #3
0
 /// <summary>
 /// Assigns a solutionId Generator to the agent which can later be used to generate solutions
 /// a new instace of the generator is created everyt time for thread safety
 /// </summary>
 /// <param name="gn"> the generator to be used</param>
 public void assignGenerator(SolutionIdGenerator gn)
 {
     // Creates a new Solution Generator Object for thread safety and assigns it once
     // to the agent
     if (this.generateId == null)
     {
         var genType    = gn.GetType();
         var parameters = new Object[3];
         parameters[0] = "all_solutions";
         parameters[1] = 100;
         parameters[2] = gn.dbapi;
         var newGenerator = Activator.CreateInstance(genType, parameters);
         generateId = (SolutionIdGenerator)newGenerator;
     }
 }