public void computeRoutes()
    {
        //RandomSearch randomSearcher = new RandomSearch ();
        //solution = randomSearcher.computeRoutes (1000);

        GeneticSearch geneticSearch = new GeneticSearch(100);

        solution = geneticSearch.computeRoutes(10000);
        solution.debugSolution();
    }
    public bool testFitness()
    {
        Chromosome  c1   = new Chromosome(new int[] { 4, 0, 1, 2, 5, 3 });
        VRPsolution csol = c1.buildSolution();

        csol.debugSolution();
//		Debug.Log (csol);
        //Chromosome c1 = new Chromosome ();
        Debug.Log("Fitness: " + c1.getFitness());

        return(true);
    }
Example #3
0
    void OnGUI()
    {
        GUI.Box(new Rect(10, 10, 300, 150), "Menu");

        if (GUI.Button(new Rect(30, 30, 200, 30), "Compute convex covers"))
        {
            foreach (Collider go in this.userInputCustomersList)
            {
                Destroy(go);                 // destroy old customers
            }
            userInputCustomersList = new LinkedList <Collider>();
            infoText.text          = "Calculating Convex Covers";
            isAutomaticConvexCover = true;
        }

        if (GUI.Button(new Rect(30, 70, 200, 30), "Set covers manually"))
        {
            foreach (Collider go in this.userInputCustomersList)
            {
                Destroy(go);                 // destroy old customers
            }
            userInputCustomersList = new LinkedList <Collider>();
            infoText.text          = "Set guarding positions by middle mouse click";
            isPositioning          = true;
        }

        if (GUI.Button(new Rect(30, 110, 200, 30), "Start patrolling"))
        {
            isPositioning = false;

            /*get customers*/
            this.customers = new Vector3[userInputCustomersList.Count];
            int i = 0;
            foreach (Collider go in this.userInputCustomersList)
            {
                this.customers[i] = go.transform.position;
                i++;
            }

            /* computer VRP */
            infoText.text = "Compute VRP..";
            VRP VRPsolver = new VRP(drones, this.customers);
            VRPsolver.computeRoutes();
            VRPsolution sol = VRPsolver.getSolution();
            sol.comunicateRoutesToDrones();
            infoText.text = "Routes communicated to drones.";
        }
    }
    public VRPsolution buildSolution()
    {
        VRPsolution          solution = new VRPsolution(drones.Length);
        Drone                currentDrone = null;
        LinkedList <Vector3> route = null;
        int i, c;

        /* Scan till the first drone */
        for (i = 0; i < Ngenes; i++)
        {
            if (isDrone(genes[i]))
            {
                /* first drone, first solution */
                currentDrone = drones[genes[i] - N];
                route        = new LinkedList <Vector3>();
                i++; i       = i % Ngenes;       // start from first customer
                break;
            }
        }

        for (/* using i from last iteration */ c = 0; c < Ngenes - 1 /*first drone scanned already*/; c++, i++, i = i % Ngenes)
        {
            if (isDrone(genes[i]))             /* it is a drone */
            {
                solution.addDrone(currentDrone, route);
                currentDrone = drones[genes[i] - N];
                route        = new LinkedList <Vector3>();
            }
            else              /* it is a customer */
            {
                route.AddLast(customersPositions[genes[i]]);
            }
        }
        solution.addDrone(currentDrone, route);
        return(solution);
    }