Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HillClimbingSearch"/> class.
 /// </summary>
 /// <param name="graph">The graph.</param>
 /// <param name="start">The start.</param>
 /// <param name="eval">The eval.</param>
 public HillClimbingSearch([NotNull] IGraph graph, uint start, [NotNull] NodeEval eval)
 {
     this.graph         = graph;
     this.currentNode   = start;
     this.currentResult = eval(start);
     this.eval          = eval;
     this.backtrace.Add(currentNode);
 }
Ejemplo n.º 2
0
        public override void Solve()
        {
            var pparser = new Pparser(FpatIn);
            int n, l;

            pparser.Fetch(out n, out l);
            var rgnode = pparser.FetchN <string>(n);

            rgnode.Insert(0, "X");
            var model = new RoutingModel(n, 1);

            model.SetFirstSolutionStrategy(RoutingModel.ROUTING_GLOBAL_CHEAPEST_ARC);
            //model.SetMetaheuristic(RoutingModel.ROUTING_TABU_SEARCH);
            model.SetCost(new NodeEval(rgnode.ToArray()));
            model.SetDepot(0);
            for (int i = 0; i < n; i++)
            {
                var varI = model.NextVar(i);
                for (int j = 0; j < n; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (!NodeEval.FMatch(rgnode[i], rgnode[j]))
                    {
                        varI.RemoveValue(j);
                    }
                }
            }
            Console.WriteLine("solving");

            Assignment solution = model.Solve();

            model.UpdateTimeLimit(1000 * 60 * 3);
            if (solution != null)
            {
                // Solution cost.
                Console.WriteLine("Cost = {0}", solution.ObjectiveValue());
                for (var inode = (int)model.Start(0); !model.IsEnd(inode); inode = (int)solution.Value(model.NextVar(inode)))
                {
                    Console.WriteLine(rgnode[inode]);
                }
                Console.WriteLine("0");
            }
        }