Пример #1
0
        public Optimization ToOptimization(bool suggestion = false)
        {
            string unoptimalReason;
            switch(Quality)
            {
                case RawQuality.Infeasible:
                case RawQuality.Unbounded:
                    if(suggestion)
                        unoptimalReason = "Suggestions could not be generated for this network, as"
                            + " the suggestion generation system  could not find an optimal solution.";
                    else
                        unoptimalReason = "This network is not solvable. Check orders for correctness."
                            + "<br /><br />If infrastructure improvements make the network solvable,"
                            + " the Suggestions tab below lists possibilities.";
                    break;

                case RawQuality.TimedOut:
                    if(suggestion)
                        unoptimalReason = "Suggestions could not be generated for this network in "
                            + "less than the maximum of " + OptimizationEngine.TIMEOUT_MAX_SECONDS*2
                            + " seconds. ";
                    else
                        unoptimalReason = "This network could not be solved in less than the maximum of "
                            + OptimizationEngine.TIMEOUT_MAX_SECONDS*2
                            + " seconds. ";
                    unoptimalReason += "<br /><br />Reduce the complexity of the network by deleting network "
                        + " elements or contact an administrator to allow longer timeouts.";
                    break;
                default:
                    unoptimalReason = null;
                    break;
            }
            var o = new Optimization()
            {
                 OptimizedNetwork = solvedNetwork,
                 TotalCost = totalCost,
                 TotalRevenue = (int)solvedNetwork.Orders.Sum(or => or.Revenue * or.Cars),
                 Optimal = Quality == RawQuality.Solved,
                 UnoptimalMessage = unoptimalReason
            };

            bool setZero = Quality != RawQuality.Solved;

            o.Nodes = solvedNetwork.Nodes.Select(n => { var no = new NodeOptimized()
            {
                Node = n,

                FlowIn = setZero ? 0 : flowDecisions.Sum(
                    v => v.Value.Sum(
                        l => l.Key.To == n ? l.Value : 0
                    )
                ),

                FlowOut = setZero ? 0 : flowDecisions.Sum(
                    v => v.Value.Sum(
                        l => l.Key.From == n ? l.Value : 0
                    )
                ),
            };
            return no; }).ToList();

            o.Links = solvedNetwork.Links.Select(l => { var lo = new LinkOptimized()
            {
                Link = l,

                Flow = setZero ? 0 : flowDecisions.Sum(
                    v => v.Value.Sum(
                        l2 => l2.Key == l ? l2.Value : 0
                    )
                ),

                CurrentTrains = setZero ? 0 : locomotiveDecisions[l]
            };
            return lo; }).ToList();

            return o;
        }
Пример #2
0
        public static void SetFrom(this Network net, Optimization oOpt)
        {
            if(net.OptimizationResult == null)
                net.OptimizationResult = oOpt;
            else
            {
                var nOpt = net.OptimizationResult;
                foreach(var node in nOpt.Nodes)
                {
                    var oNode = oOpt.Nodes.FirstOrDefault(no => no.Node == node.Node);

                    node.FlowIn = oNode.FlowIn;

                    node.FlowOut = oNode.FlowOut;
                }
                foreach(var link in nOpt.Links)
                {
                    var oLink = oOpt.Links.FirstOrDefault(lo => lo.Link == link.Link);

                    link.Flow = oLink.Flow;
                    link.CurrentTrains = oLink.CurrentTrains;
                }
                nOpt.Optimal = oOpt.Optimal;
                nOpt.UnoptimalMessage = oOpt.UnoptimalMessage;
                nOpt.TotalCost = oOpt.TotalCost;
                nOpt.TotalRevenue = oOpt.TotalRevenue;
            }
        }