Exemple #1
0
        public static void Main(string[] args)
        {
            Queue <IterationContext> cq = new Queue <IterationContext>();
            int    start    = 0;
            int    antCount = 100;
            double alpha    = .27;
            double beta     = 8.8;
            double pheromoneEvaporationCoef = 0.7;
            double pheromoneConstant        = 250;
            int    maxIters = 100;

            if (args[0] == "-genarate")
            {
                int numOfGraphs = 1;
                int maxNodes    = 20;
                int minNodes    = 5;
                int maxWeight   = 3000;
                int minWeight   = 500;

                Generator g = new Generator(numOfGraphs, maxNodes, minNodes, maxWeight, minWeight);

                var graphs = g.generate(); //array of matricies of graphs

                Console.WriteLine("Graphs generated");
                foreach (LowerTriangularMatrix <double> lt in graphs)
                {
                    lt.writeToFile("test.txt");
                    Console.WriteLine(lt.size);
                    begin(lt, start, antCount, alpha, beta, pheromoneEvaporationCoef, pheromoneConstant
                          , maxIters, cq);
                }
            }
            else if (args[0] == "-run")
            {
                LowerTriangularMatrix <double> lt = new LowerTriangularMatrix <double>(0);
                lt.readFromFile(args[1]);
                begin(lt, start, antCount, alpha, beta, pheromoneEvaporationCoef, pheromoneConstant
                      , maxIters, cq);
            }
            else if (args[0] == "-genetic")
            {
                GeneticAlg g = new GeneticAlg(5000);
                g.start();
            }
            else
            {
                Console.WriteLine("Need an option besides [-generate,-genetic,-run <path>]? Add it :D");
                return;
            }
        }
Exemple #2
0
    void Awake()
    {
        instance   = this;
        generation = 1;
        timer      = 0.0f;

        landerPos = new Vector3(Random.Range(-16, 17), 0, Random.Range(10, 16));
        for (int i = 0; i < lunarsNum; i++)
        {
            GameObject obj = Instantiate(landerPrefab, landerPos, Quaternion.Euler(90, 0, 0));
            Lander     lan = obj.GetComponent <Lander>();
            lan.SetBrain(inputs, outputs, numHiddenLayers, numNeuronPerHiddenLayer, bias, sigmoidPending);
            lan.SetLimits(maxHeight, maxWidth);
            if (i == 0)
            {
                ga = new GeneticAlg(elitesNum, lunarsNum, lan.GetNumberOfWeights(), mutation);
            }
            landers.Add(lan);
        }
        plataform = Instantiate(plataformPrefab, new Vector3(Random.Range(-17, 18), 0, Random.Range(-15, -9)), Quaternion.Euler(90, 0, 0));
    }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        genAlg = new GeneticAlg();


        int totalWeights = ((nnSettings.numInputs + 1) * nnSettings.numNeuronsPerHidden)
                           + (nnSettings.numNeuronsPerHidden + 1) * nnSettings.numOutputs;

        genAlg.GenerateNewPopulation(populationPerGeneration, totalWeights);
        currentAgentFitness = 0.0f;
        bestFitness         = 0.0f;

        currentTimer = 0.0f;

        neuralNet = new NeuralNet();
        neuralNet.CreateNet(1, nnSettings.numInputs, nnSettings.numNeuronsPerHidden, nnSettings.numOutputs);
        Genome genome = genAlg.GetNextGenome();

        //neuralNet.FromGenome (genome, 5, 8, 2);
        neuralNet.FromGenome(genome, nnSettings.numInputs, nnSettings.numNeuronsPerHidden, nnSettings.numOutputs);
    }
Exemple #4
0
    // Use this for initialization
    void Awake()
    {
        instance   = this;
        generation = 1;
        for (int i = 0; i < mineNum; i++)
        {
            GameObject obj = Instantiate(mine, new Vector3(Random.Range(1 - (float)maxWidth, (float)maxWidth) - 1, 0, Random.Range(1 - (float)maxHeight, (float)maxHeight - 1)), Quaternion.Euler(0, 0, 0));
            obj.GetComponent <Mine>().SetLimits(maxHeight, maxWidth);
            mines.Add(obj);
        }

        for (int i = 0; i < agentNum; i++)
        {
            GameObject obj  = Instantiate(agent, new Vector3(Random.Range(1 - (float)maxWidth, (float)maxWidth) - 1, 0, Random.Range(1 - (float)maxHeight, (float)maxHeight - 1)), Quaternion.Euler(0, Random.Range(0.0f, 360.0f), 0));
            Tank       tank = obj.GetComponent <Tank>();
            tank.SetLimits(maxHeight, maxWidth);
            tank.SetBrain(inputs, outputs, numHiddenLayers, numNeuronPerHiddenLayer, bias, sigmoidPending);
            if (i == 0)
            {
                ga = new GeneticAlg(elitesNum, agentNum, tank.GetNumberOfWeights(), mutation);
            }
            agents.Add(tank);
        }
    }
Exemple #5
0
 /// <summary>
 /// Start is called on the frame when a script is enabled just before
 /// any of the Update methods is called the first time.
 /// </summary>
 void Start()
 {
     AIControl = GetComponent <GeneticAlg>();
 }