A super class of local search solvers, and also an implementation of a random walk solver. Local search is an iterative procedure. It first finds an initial soluttion, and iteratively make a small change
Inheritance: Solver
Ejemplo n.º 1
0
    public static void Main(String[] args)
    {
        String problem = "ft10";
        long timeout = 1000 * 60 * 10;
        String[] solverNames = new String[] { "sa", "ibb", "taboo" };
        int i = 0;
        if (i < args.Length)
            problem = args[i++];
        if (i < args.Length)
            timeout = Int32.Parse(args[i++]) * 1000;
        if (i < args.Length)
        {
            solverNames = new String[args.Length - i];
            int j = 0;
            for (; i < args.Length; i++)
            {
                solverNames[j++] = args[i];
            }
        }
        Network network = (new JSSPProblem(problem)).network();
        if (network == null)
            return;
        //int opt = Solver.MINIMIZE | Solver.BETTER;
        int opt = Solver.Default;
        Solver[] solvers = new Solver[solverNames.Length];
        for (i = 0; i < solvers.Length; i++)
        {
            String name = solverNames[i];
            if (name.Equals("sa"))
            {
                solvers[i] = new SimulatedAnneallingSearch((Network)network.Clone(), opt, name);
            }
            else if (name.Equals("ibb"))
            {
                solvers[i] = new IterativeBranchAndBoundSearch((Network)network.Clone(), opt, name);
            }
            else if (name.Equals("taboo") || name.Equals("tabu"))
            {
                solvers[i] = new TabooSearch((Network)network.Clone(), opt, name);
            }
            else if (name.Equals("rw"))
            {
                solvers[i] = new LocalSearch((Network)network.Clone(), opt, name);
            }
            else
            {
                Console.Out.WriteLine("Unknown solver name " + name);
                solvers[i] = null;
            }
        }
        Solver all = new ParallelSolver(solvers);

        //Monitor monitor = new Monitor();
         //monitor.setX(0, (int)(timeout/1000));
        //all.setMonitor(monitor);
        //SolutionHandler sh=null;
        Solution solution = all.FindBest(timeout);
        Console.Out.WriteLine(solution);
        Console.In.ReadLine();
    }
Ejemplo n.º 2
0
    public static void Main(String[] args)
    {
        Network net = new Network();
        ft06(net);

        String solverName = "ibb";
        int opt = Solver.Minimize;
        long timeout = 180000;
        if (args.Length >= 1)
        {
            solverName = args[0];
        }

        Solver solver;
        if (solverName.Equals("bb"))
        {
            solver = new DefaultSolver(net, opt, "bb");
        }
        else if (solverName.Equals("random"))
        {
            solver = new LocalSearch(net, opt, "rs");
        }
        else if (solverName.Equals("sa"))
        {
            solver = new SimulatedAnneallingSearch(net, opt, "sa");
        }
        else if (solverName.Equals("ibb"))
        {
            solver = new IterativeBranchAndBoundSearch(net, opt, "ibb");
        }
        else if (solverName.Equals("taboo"))
        {
            solver = new TabooSearch(net, opt, "taboo");
        }
        else
        {
            Solver sa = new SimulatedAnneallingSearch((Network)net.Clone(), opt, "sa");
            Solver ibb = new IterativeBranchAndBoundSearch((Network)net.Clone(), opt, "ibb");
            solver = new ParallelSolver(new Solver[] { sa, ibb });
        }
        //Cream.Monitor monitor = new Monitor();
        //monitor.setX(0, (int)(timeout / 1000));
        //solver.setMonitor(monitor);

        Console.Out.WriteLine("Start " + solver + ", timeout = " + timeout + " msecs");

        Solution bestSolution;
        int c = 0;
        if (true)
        {
            for (solver.Start(timeout); solver.WaitNext(); solver.Resume())
            {
                Solution solution = solver.Solution;
                Console.Out.WriteLine(++c);
                Console.Out.WriteLine(solution);
                int value_Renamed = solution.ObjectiveIntValue;
                Console.Out.WriteLine(value_Renamed);
                Console.Out.WriteLine("=======================");
            }
            solver.Stop();
            bestSolution = solver.BestSolution;
        }
        else
        {
            bestSolution = solver.FindBest(timeout);
        }

        Console.Out.WriteLine("Best = " + bestSolution.ObjectiveIntValue);
        Console.Out.WriteLine("Best = " + bestSolution);
        Console.In.ReadLine();
    }