Example #1
0
        /// <summary>
        /// Fills persisted <see cref="ParameterPurpose.Persistence"/> parameters of the process
        /// </summary>
        /// <param name="processInstance">Instance of the process</param>
        public void FillPersistedProcessParameters(ProcessInstance processInstance)
        {
            var persistenceParameters = processInstance.ProcessScheme.PersistenceParameters.ToList();
            var parameters            = new List <ParameterDefinitionWithValue>(persistenceParameters.Count());

            var db = _connector.GetDatabase();
            var persistedParametersValue = db.StringGet(GetKeyForProcessPersistence(processInstance.ProcessId));

            if (!persistedParametersValue.HasValue)
            {
                return;
            }

            var persistedParameters = JsonConvert.DeserializeObject <Dictionary <string, string> >(persistedParametersValue);

            foreach (var persistedParameter in persistedParameters)
            {
                var parameterDefinition = persistenceParameters.FirstOrDefault(p => p.Name == persistedParameter.Key);
                if (parameterDefinition == null)
                {
                    parameterDefinition = ParameterDefinition.Create(persistedParameter.Key, typeof(UnknownParameterType), ParameterPurpose.Persistence);
                    parameters.Add(ParameterDefinition.Create(parameterDefinition, persistedParameter.Value));
                }
                else
                {
                    parameters.Add(ParameterDefinition.Create(parameterDefinition, ParametersSerializer.Deserialize(persistedParameter.Value, parameterDefinition.Type)));
                }
            }

            processInstance.AddParameters(parameters);
        }
Example #2
0
        private IEnumerable <ParameterDefinitionWithValue> GetPersistedProcessParameters(Guid processId, ProcessDefinition processDefinition)
        {
            var persistenceParameters = processDefinition.PersistenceParameters.ToList();
            var parameters            = new List <ParameterDefinitionWithValue>(persistenceParameters.Count());

            List <WorkflowProcessInstancePersistence> persistedParameters;
            var dbcoll  = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName);
            var process = dbcoll.Find(x => x.Id == processId).FirstOrDefault();

            if (process != null && process.Persistence != null)
            {
                persistedParameters = process.Persistence.ToList();
            }
            else
            {
                return(parameters);
                //persistedParameters = new List<WorkflowProcessInstancePersistence>();
            }

            foreach (var persistedParameter in persistedParameters)
            {
                var parameterDefinition = persistenceParameters.FirstOrDefault(p => p.Name == persistedParameter.ParameterName);
                if (parameterDefinition == null)
                {
                    parameterDefinition = ParameterDefinition.Create(persistedParameter.ParameterName, typeof(UnknownParameterType), ParameterPurpose.Persistence);
                    parameters.Add(ParameterDefinition.Create(parameterDefinition, persistedParameter.Value));
                }
                else
                {
                    parameters.Add(ParameterDefinition.Create(parameterDefinition, ParametersSerializer.Deserialize(persistedParameter.Value, parameterDefinition.Type)));
                }
            }

            return(parameters);
        }
Example #3
0
        public static void Main(string[] args)
        {
            var nodeParamsDeserialize = new ParametersSerializer<NodeParameters>();
              var nodeParams = nodeParamsDeserialize.Deserialize("nodeParams.xml");
              var machineManager = new MachineManager(nodeParams.Ip, nodeParams.Ports.ToArray());
              if (nodeParams.PeerAddress != null)
              {
            machineManager.Register(nodeParams.PeerAddress);

              }
              var cont = true;
              while (cont)
              {
            PrintMenu();
            var c = Console.ReadKey().KeyChar;
            Console.WriteLine("\n\n");

            switch (c)
            {
              case '1':
            var r = PerformCalculations(machineManager);
            Console.WriteLine("Value: {0}", r.FitnessValue[0]);
            break;
              case '0':
            cont = false;
            break;
            }
              }
        }
Example #4
0
        private IEnumerable <ParameterDefinitionWithValue> GetPersistedProcessParameters(Guid processId, ProcessDefinition processDefinition)
        {
            var persistenceParameters = processDefinition.PersistenceParameters.ToList();
            var parameters            = new List <ParameterDefinitionWithValue>(persistenceParameters.Count());

            List <WorkflowProcessInstancePersistence> persistedParameters;

            using (var connection = new NpgsqlConnection(ConnectionString))
            {
                persistedParameters = WorkflowProcessInstancePersistence.SelectByProcessId(connection, processId).ToList();
            }

            foreach (var persistedParameter in persistedParameters)
            {
                var parameterDefinition = persistenceParameters.FirstOrDefault(p => p.Name == persistedParameter.ParameterName);
                if (parameterDefinition == null)
                {
                    parameterDefinition = ParameterDefinition.Create(persistedParameter.ParameterName, typeof(UnknownParameterType), ParameterPurpose.Persistence);
                    parameters.Add(ParameterDefinition.Create(parameterDefinition, persistedParameter.Value));
                }
                else
                {
                    parameters.Add(ParameterDefinition.Create(parameterDefinition, ParametersSerializer.Deserialize(persistedParameter.Value, parameterDefinition.Type)));
                }
            }

            return(parameters);
        }
Example #5
0
        public static void Main(string[] args)
        {
            var nodeParamsDeserialize = new ParametersSerializer <NodeParameters>();
            var nodeParams            = nodeParamsDeserialize.Deserialize("nodeParams.xml");
            var machineManager        = new MachineManager(nodeParams.Ip, nodeParams.Ports.ToArray());

            if (nodeParams.PeerAddress != null)
            {
                machineManager.Register(nodeParams.PeerAddress);
            }
            var cont = true;

            while (cont)
            {
                PrintMenu();
                var c = Console.ReadKey().KeyChar;
                Console.WriteLine("\n\n");

                switch (c)
                {
                case '1':
                    var r = PerformCalculations(machineManager);
                    Console.WriteLine("Value: {0}", r.FitnessValue[0]);
                    break;

                case '0':
                    cont = false;
                    break;
                }
            }
        }
Example #6
0
        private static ParticleState PerformCalculations(MachineManager machineManager)
        {
            var psoParamsDeserialize = new ParametersSerializer<PsoParameters>();
              var psoParams = psoParamsDeserialize.Deserialize("psoParams.xml");

              machineManager.StartPsoAlgorithm(psoParams);
              return machineManager.GetResult();
        }
Example #7
0
        private static ParticleState PerformCalculations(MachineManager machineManager)
        {
            var psoParamsDeserialize = new ParametersSerializer <PsoParameters>();
            var psoParams            = psoParamsDeserialize.Deserialize("psoParams.xml");

            machineManager.StartPsoAlgorithm(psoParams);
            return(machineManager.GetResult());
        }
Example #8
0
        private static object DeserializeValue(NameValueCollection formParameters, string key, Type type)
        {
            object value = null;

            try
            {
                value = ParametersSerializer.Deserialize(formParameters[key], type);
            }
            catch (Exception)
            {
                if (type == typeof(string))
                {
                    value = formParameters[key];
                }
                else
                {
                    throw;
                }
            }
            return(value);
        }
Example #9
0
        private IEnumerable <ParameterDefinitionWithValue> GetPersistedProcessParameters(Guid processId, ProcessDefinition processDefinition)
        {
            var persistenceParameters = processDefinition.PersistenceParameters.ToList();
            var parameters            = new List <ParameterDefinitionWithValue>(persistenceParameters.Count());

            List <WorkflowProcessInstancePersistence> persistedParameters;

            using (var session = Store.OpenSession())
            {
                var process = session.Load <WorkflowProcessInstance>(processId);
                if (process != null && process.Persistence != null)
                {
                    persistedParameters = process.Persistence;
                }
                else
                {
                    return(parameters);
                    //persistedParameters = new List<WorkflowProcessInstancePersistence>();
                }
            }

            foreach (var persistedParameter in persistedParameters)
            {
                var parameterDefinition = persistenceParameters.FirstOrDefault(p => p.Name == persistedParameter.ParameterName);
                if (parameterDefinition == null)
                {
                    parameterDefinition = ParameterDefinition.Create(persistedParameter.ParameterName, typeof(UnknownParameterType), ParameterPurpose.Persistence);
                    parameters.Add(ParameterDefinition.Create(parameterDefinition, persistedParameter.Value));
                }
                else
                {
                    parameters.Add(ParameterDefinition.Create(parameterDefinition, ParametersSerializer.Deserialize(persistedParameter.Value, parameterDefinition.Type)));
                }
            }

            return(parameters);
        }
Example #10
0
        static void Main(string[] args)
        {
            var timeStr = DateTime.Now.Hour.ToString("D2") + DateTime.Now.Minute.ToString("D2");

            var nodeParamsDeserialize = new ParametersSerializer <NodeParameters>();
            var psoParamsDeserialize  = new ParametersSerializer <PsoParameters>();
            var nodeParams            = nodeParamsDeserialize.Deserialize("nodeParams.xml");
            var psoParams             = psoParamsDeserialize.Deserialize("psoParams.xml");

            MachineManager machineManager = new MachineManager(nodeParams.Ip, nodeParams.Ports.ToArray(), nodeParams.NrOfVCpu);

            if (nodeParams.PeerAddress != null)
            {
                try
                {
                    machineManager.Register(nodeParams.PeerAddress);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unexpected error occured. Plase try to connect once again.");
                    return;
                }
                Console.WriteLine("Working...");
                Console.WriteLine("Press ENTER to finish");
                ConsoleKeyInfo pressed = new ConsoleKeyInfo();
                while (pressed.Key != ConsoleKey.Enter)
                {
                    pressed = Console.ReadKey();
                }
                ;
            }
            else
            {
                if (args.Length < 3)
                {
                    Console.WriteLine("CocoClusterApp <Dim1[,Dim2,Dim3...]> <FunctionsFrom> <FunctionsTo> <Budget>");
                    return;
                }
                var dims             = args[0];
                var functionsFrom    = int.Parse(args[1]);
                var functionsTo      = int.Parse(args[2]);
                var budgetMultiplier = int.Parse(args[3]);

                var randomGenerator = RandomGenerator.GetInstance(RandomSeed);
                CocoLibraryWrapper.cocoSetLogLevel("warning");

                var functionsToOptimize = new List <string>();
                for (var i = functionsFrom; i <= functionsTo; i++)
                {
                    functionsToOptimize.Add(string.Format("f{0:D3}", i));
                }
                Console.WriteLine("Press any key on the keyboard when ready...");
                Console.ReadKey();
                Console.WriteLine("Running the example experiment... (might take time, be patient)");
                try
                {
                    /* Set some options for the observer. See documentation for other options. */
                    var observerOptions =
                        "result_folder: " +
                        String.Format("{0}P_{1}G", psoParams.ParticleIterationsToRestart,
                                      psoParams.PsoIterationsToRestart)
                        + " algorithm_name: PSO"
                        + " algorithm_info: \"A simple Random search algorithm\"";
                    /* Initialize the suite and observer */
                    var suite     = new Suite("bbob", "year: 2016", "dimensions: " + dims);
                    var observer  = new Observer("bbob", observerOptions);
                    var benchmark = new Benchmark(suite, observer);
                    /* Iterate over all problems in the suite */
                    var evalLogger = new EvaluationsLogger();
                    PsoServiceLocator.Instance.Register <EvaluationsLogger>(evalLogger);
                    var fileLogger = new FileLogger("evals.csv");
                    fileLogger.Log("function_id,gpu_evals,cpu_evals,gpu/cpu");
                    int instanceCounter = 0;
                    while ((Problem = benchmark.getNextProblem()) != null)
                    {
                        instanceCounter = (instanceCounter + 1) % 15;
                        if (instanceCounter == 0)
                        {
                            evalLogger.RestartCounters();
                        }
                        var             restarts = -1;
                        FitnessFunction function;
                        if (!functionsToOptimize.Contains(Problem.FunctionNumber))
                        {
                            continue;
                        }
                        var settings        = SetupOptimizer(psoParams, out function);
                        var evaluations     = (long)settings.FunctionParameters.Dimension * budgetMultiplier;
                        var evaluationsLeft = evaluations;

                        do
                        {
                            restarts++;


                            settings.Iterations =
                                (int)Math.Ceiling(evaluations / ((double)settings.Particles.Sum(pc => pc.Count)));
                            //var sendParams = new PsoParameters()
                            //{
                            //    Iterations = psoParams.Iterations,
                            //    TargetValueCondition = psoParams.TargetValueCondition,
                            //    IterationsLimitCondition = psoParams.IterationsLimitCondition,
                            //    PsoIterationsToRestart = psoParams.PsoIterationsToRestart,
                            //    ParticleIterationsToRestart = psoParams.ParticleIterationsToRestart,
                            //    Epsilon = psoParams.Epsilon,
                            //    FunctionParameters = psoParams.FunctionParameters,
                            //    ParticlesCount = 20,
                            //    Particles = new ParticlesCount[1] { new ParticlesCount(PsoParticleType.Standard, 20)}
                            //};
                            machineManager.StartPsoAlgorithm(psoParams);
                            machineManager.GetResult();

                            var evalsDone = Problem.getEvaluations();
                            evaluationsLeft = evaluations - evalsDone;
                        } while (!Problem.isFinalTargetHit() && evaluationsLeft > 0);
                        evalLogger.IncreaseCpuEvals((int)Problem.getEvaluations());
                        Console.WriteLine("{0} | {1} evaluations | {2} restarts | {3:e} BestEval ", Problem.Id, Problem.getEvaluations(), restarts, function.BestEvaluation.FitnessValue[0]);

                        if (instanceCounter == 14)
                        {
                            fileLogger.Log(String.Format("{0},{1},{2},{3}", Problem.Id.Substring(5, 4), evalLogger._cpuEvaluations, evalLogger._gpuEvaluations, evalLogger.Ratio));
                        }
                    }
                    fileLogger.GenerateLog();
                    benchmark.finalizeBenchmark();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }



            Console.WriteLine("Done");
        }
Example #11
0
        static void Main(string[] args)
        {
            var timeStr = DateTime.Now.Hour.ToString("D2") + DateTime.Now.Minute.ToString("D2");

            var nodeParamsDeserialize = new ParametersSerializer<NodeParameters>();
            var psoParamsDeserialize = new ParametersSerializer<PsoParameters>();
            var nodeParams = nodeParamsDeserialize.Deserialize("nodeParams.xml");
            var psoParams = psoParamsDeserialize.Deserialize("psoParams.xml");

            MachineManager machineManager = new MachineManager(nodeParams.Ip, nodeParams.Ports.ToArray(), nodeParams.NrOfVCpu);
            if (nodeParams.PeerAddress != null)
            {
              try
              {
                machineManager.Register(nodeParams.PeerAddress);

              }
              catch (Exception e)
              {
                Console.WriteLine("Unexpected error occured. Plase try to connect once again.");
                return;
              }
                Console.WriteLine("Working...");
                Console.WriteLine("Press ENTER to finish");
                ConsoleKeyInfo pressed = new ConsoleKeyInfo();
                while (pressed.Key != ConsoleKey.Enter)
                {
                    pressed = Console.ReadKey();
                };
            }
            else
            {
                if (args.Length < 3)
                {
                    Console.WriteLine("CocoClusterApp <Dim1[,Dim2,Dim3...]> <FunctionsFrom> <FunctionsTo> <Budget>");
                    return;
                }
                var dims = args[0];
                var functionsFrom = int.Parse(args[1]);
                var functionsTo = int.Parse(args[2]);
                var budgetMultiplier = int.Parse(args[3]);

                var randomGenerator = RandomGenerator.GetInstance(RandomSeed);
                CocoLibraryWrapper.cocoSetLogLevel("warning");

                var functionsToOptimize = new List<string>();
                for (var i = functionsFrom; i <= functionsTo; i++)
                {
                    functionsToOptimize.Add(string.Format("f{0:D3}", i));
                }
                Console.WriteLine("Press any key on the keyboard when ready...");
                Console.ReadKey();
                Console.WriteLine("Running the example experiment... (might take time, be patient)");
                try
                {

                    /* Set some options for the observer. See documentation for other options. */
                    var observerOptions =
                        "result_folder: " +
                        String.Format("{0}P_{1}G", psoParams.ParticleIterationsToRestart,
                            psoParams.PsoIterationsToRestart)
                        + " algorithm_name: PSO"
                        + " algorithm_info: \"A simple Random search algorithm\"";
                    /* Initialize the suite and observer */
                    var suite = new Suite("bbob", "year: 2016", "dimensions: " + dims);
                    var observer = new Observer("bbob", observerOptions);
                    var benchmark = new Benchmark(suite, observer);
                    /* Iterate over all problems in the suite */
                    var evalLogger = new EvaluationsLogger();
                    PsoServiceLocator.Instance.Register<EvaluationsLogger>(evalLogger);
                    var fileLogger = new FileLogger("evals.csv");
                    fileLogger.Log("function_id,gpu_evals,cpu_evals,gpu/cpu");
                    int instanceCounter = 0;
                    while ((Problem = benchmark.getNextProblem()) != null)
                    {
                        instanceCounter = (instanceCounter + 1) % 15;
                        if(instanceCounter == 0)
                        {
                            evalLogger.RestartCounters();
                        }
                        var restarts = -1;
                        FitnessFunction function;
                        if (!functionsToOptimize.Contains(Problem.FunctionNumber)) continue;
                        var settings = SetupOptimizer(psoParams, out function);
                        var evaluations = (long) settings.FunctionParameters.Dimension * budgetMultiplier;
                        var evaluationsLeft = evaluations;

                        do
                        {
                            restarts++;

                            settings.Iterations =
                                (int)Math.Ceiling(evaluations / ((double)settings.Particles.Sum(pc => pc.Count)));
                            //var sendParams = new PsoParameters()
                            //{
                            //    Iterations = psoParams.Iterations,
                            //    TargetValueCondition = psoParams.TargetValueCondition,
                            //    IterationsLimitCondition = psoParams.IterationsLimitCondition,
                            //    PsoIterationsToRestart = psoParams.PsoIterationsToRestart,
                            //    ParticleIterationsToRestart = psoParams.ParticleIterationsToRestart,
                            //    Epsilon = psoParams.Epsilon,
                            //    FunctionParameters = psoParams.FunctionParameters,
                            //    ParticlesCount = 20,
                            //    Particles = new ParticlesCount[1] { new ParticlesCount(PsoParticleType.Standard, 20)}
                            //};
                            machineManager.StartPsoAlgorithm(psoParams);
                            machineManager.GetResult();

                            var evalsDone = Problem.getEvaluations();
                            evaluationsLeft  = evaluations - evalsDone;
                        } while (!Problem.isFinalTargetHit() && evaluationsLeft > 0 );
                        evalLogger.IncreaseCpuEvals((int)Problem.getEvaluations());
                        Console.WriteLine("{0} | {1} evaluations | {2} restarts | {3:e} BestEval ", Problem.Id, Problem.getEvaluations(), restarts, function.BestEvaluation.FitnessValue[0]);

                        if(instanceCounter == 14)
                        {
                            fileLogger.Log(String.Format("{0},{1},{2},{3}", Problem.Id.Substring(5,4), evalLogger._cpuEvaluations, evalLogger._gpuEvaluations, evalLogger.Ratio));
                        }

                    }
                    fileLogger.GenerateLog();
                    benchmark.finalizeBenchmark();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

            }

            Console.WriteLine("Done");
        }