Example #1
0
        public void MergeThreadFunc(Solutions msg, ComputationalThread thread)
        {
            var asm = Assembly.Load(AssemblyName.GetAssemblyName(Path.GetFullPath(msg.ProblemType + ".dll")));//Assembly.LoadFile(Path.GetFullPath("DVRP.dll"));
            //Type t = asm.GetType("DVRP.DVRP");
            Type t = asm.GetTypes().Where(x => x.IsSubclassOf(typeof(UCCTaskSolver.TaskSolver))).FirstOrDefault();
            if (t == null)
                throw new ArgumentException("Brak odpowiedniej klasy w module.");

            var methodInfo = t.GetMethod("MergeSolution");

            object[] constructor_param = new object[1];
            constructor_param[0] = msg.CommonData;

            var o = Activator.CreateInstance(t, constructor_param);

            Solutions solutions_msg;
            object[] param = new object[1];
            param[0] = PartialSolutions[msg.Id].ToArray();
            try
            {
                methodInfo.Invoke(o, param);
            }
            catch (Exception e)
            {
                MessageBox.Show("Moduł '" + msg.ProblemType + ".dll' zakończył działanie z błędem:\n\n" + e.InnerException.Message, "Błąd modułu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            var meth = t.GetMethod("get_Solution");

            byte[] ans = (byte[])meth.Invoke(o, null);

            // TimeSpan ts = DateTime.Now - start_time;

            Solution final_solution = new Solution(msg.Id, false, SolutionType.Final, thread.HowLong, ans);
            List<Solution> solution_to_send = new List<Solution>();
            solution_to_send.Add(final_solution);

            solutions_msg = new Solutions(msg.ProblemType, msg.Id, msg.CommonData, solution_to_send);

            client.Work(solutions_msg.GetXmlData());
            SetComputationalThreadIdle((ulong)thread.ProblemInstanceId, (ulong)thread.TaskId);
        }
        public void SolutionConstructorTest()
        {
            //Arrange
            byte[] data = new byte[0];

            //Act
            Solution solution = new Solution(0, true, SolutionType.Final, 120, data);

            //Assert
            Assert.IsNotNull(solution);
        }
Example #3
0
        public void NodeThreadFunc(/*object o, MethodInfo methodInfo,*/ SolvePartialProblems msg, PartialProblem pp, ComputationalThread ct)
        {
            DateTime start_time = DateTime.Now;

            var asm = Assembly.Load(AssemblyName.GetAssemblyName(Path.GetFullPath(msg.ProblemType + ".dll")));
            //Type t = asm.GetType("DVRP.DVRP");
            Type t = asm.GetTypes().Where(x => x.IsSubclassOf(typeof(UCCTaskSolver.TaskSolver))).FirstOrDefault();

            var methodInfo = t.GetMethod("Solve");
            object[] constructor_params = new object[1];
            constructor_params[0] = msg.CommonData;
            var o = Activator.CreateInstance(t, constructor_params);
            /*********event handler*/

            var eventInfo = t.GetEvent("SolutionsMergingFinished");
            Type tDelegate = eventInfo.EventHandlerType;

            MethodInfo addHandler = eventInfo.GetAddMethod();

            Type returnType = GetDelegateReturnType(tDelegate);
            Console.WriteLine(returnType.ToString());

            DynamicMethod handler = new DynamicMethod("", null,
                                  GetDelegateParameterTypes(tDelegate), t);

            ILGenerator ilgen = handler.GetILGenerator();

            Type[] showParameters = { typeof(String) };
            MethodInfo simpleShow = typeof(CNNode).GetMethod("SetComputationalThreadIdle");
            Console.WriteLine(simpleShow.ToString());

            ilgen.Emit(OpCodes.Ldstr, "string");//ct.ProblemInstanceId.Value);//Ldstr,"This event handler was constructed at run time.");
            ilgen.Emit(OpCodes.Call, simpleShow);
            //   ilgen.Emit(OpCodes.Pop);
            ilgen.Emit(OpCodes.Ret);

            // Complete the dynamic method by calling its CreateDelegate
            // method. Use the "add" accessor to add the delegate to
            // the invocation list for the event.
            //
            Delegate dEmitted = handler.CreateDelegate(tDelegate);
            addHandler.Invoke(o, new Object[] { dEmitted });

            if (methodInfo != null)
            {
                object[] param = new object[2];

                param[0] = pp.Data;
                if (msg.SolvingTimeout == null)
                    param[1] = null;
                else param[1] = new TimeSpan((long)msg.SolvingTimeout * 10000000);

                byte[] result = null;

                try
                {
                    result = (byte[])methodInfo.Invoke(o, param);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Moduł '" + msg.ProblemType + ".dll' zakończył działanie z błędem:\n\n" + e.InnerException.Message, "Błąd modułu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }

                TimeSpan ts = DateTime.Now - start_time;
                Solution s = new Solution(pp.TaskId, false, SolutionType.Partial, (ulong)ts.TotalSeconds, result);

                solution.Add(s);
                Console.WriteLine("sending partial solutions");
                Solutions solutions = new Solutions(msg.ProblemType, msg.Id, msg.CommonData, solution);

                client.Work(solutions.GetXmlData());

                SetComputationalThreadIdle(msg.Id, pp.TaskId);
            }
            else Console.WriteLine("Method equal to null");
        }
        public void SolutionsConstructorTest()
        {
            //Arrange
            byte[] commonData = new byte[0];
            Solution[] solutionsArray = new Solution[]{new Solution(0, true, SolutionType.Ongoing, 120, new byte[0])};

            //Act
            Solutions solutions = new Solutions("name", 0, commonData, solutionsArray);

            //Assert
            Assert.IsNotNull(solutions);
        }
Example #5
0
        /// <summary>
        /// Metoda zwraca pusty obiekt Solution
        /// </summary>
        /// <returns>Obiekt solution</returns>
        public static Solution GetEmptySolution()
        {
            Solution s = new Solution();
            s.ComputationsTime = ulong.MaxValue;

            return s;
        }