public void PartialProblemParsingTest()
        {
            var visits = new int [3][];

            visits[0]    = new int[1];
            visits[0][0] = 1;
            visits[1]    = new int[1];
            visits[1][0] = 2;
            visits[2]    = new int[1];
            visits[2][0] = 3;
            var instance = new DVRPPartialProblemInstance()
            {
                PartialResult  = 0,
                SolutionResult = SolutionResult.NotSolved,
                VisitIds       = visits
            };
            var converter = new ProblemToBytesConverter();
            var bytes     = converter.ToByteArray(instance);
            var ret       = (DVRPPartialProblemInstance)converter.FromBytesArray(bytes);

            //assertions:
            Assert.AreEqual(visits.Length, ret.VisitIds.Length);
            Assert.AreEqual(visits[0].Length, ret.VisitIds[0].Length);
            Assert.AreEqual(visits[1].Length, ret.VisitIds[1].Length);
            Assert.AreEqual(visits[2].Length, ret.VisitIds[2].Length);
            Assert.AreEqual(visits[0][0], ret.VisitIds[0][0]);
            Assert.AreEqual(visits[1][0], ret.VisitIds[1][0]);
            Assert.AreEqual(visits[2][0], ret.VisitIds[2][0]);
            Assert.AreEqual(ret.PartialResult, 0);
            Assert.AreEqual(ret.SolutionResult, SolutionResult.NotSolved);
        }
Пример #2
0
        public void DvrpPartialProblemInstanceSerializationTest()
        {
            var problem = new DVRPPartialProblemInstance();

            problem.SolutionResult = SolutionResult.Successful;
            problem.PartialResult  = 123;
            problem.VisitIds       = new int[][]
            {
                new int[] { 1, 3, 5, 7, 9 },
                new int[] { 0, 2, 4, 6 },
                new int[] { 11, 22 }
            };
            string xml = _serializer.ToXmlString(problem);
            DVRPPartialProblemInstance p = (DVRPPartialProblemInstance)_serializer.FromXmlString(xml);

            Assert.AreEqual(problem.SolutionResult, p.SolutionResult);
            Assert.AreEqual(problem.PartialResult, p.PartialResult);
            Assert.AreEqual(problem.VisitIds[2][1], p.VisitIds[2][1]);
        }
        /// <summary>
        /// this will do something with final solution, e.g. printing it
        /// </summary>
        /// <param name="solution"></param>
        public void PrintSolutionResult(SolutionsSolution solution)
        {
            if (solution.Data == null)
            { 
                log.DebugFormat("Result - solution received is null");
                return;
            }

        DVRPPartialProblemInstance result = (DVRPPartialProblemInstance) _problemConverter.FromBytesArray(solution.Data);
            if (result.SolutionResult == SolutionResult.Impossible)
            {
                log.DebugFormat("Result - solution unknown - problem impossible to solve");
            }
            else if (result.SolutionResult == SolutionResult.NotSolved)
            {
                log.DebugFormat("Error of cluster computations. Cluster sent solution with field NotSolved");
            }
            else
                log.DebugFormat("Result - solution found, minimal cost = {0} ", result.PartialResult);
            return;
        }