Example #1
0
        //Creates an output list.
        //For each arc a double[] is created and placed in the list.
        //The array length is the number of possible restrictions
        //If an arc has a restriction, the position in the array corresponding to the same
        //type number of a restriction - 1, gets the value 1, the rest 0. e.g {0, 1, 0, 0} type 2
        public static double[][] CreateOutputList(Network_DTO network)
        {
            int nrOfRestrictions = network.restrictions.Count();

            double[][] outputList = new double[network.arcs.Count()][];
            int        listNr     = 0;

            foreach (Arc_DTO arc in network.arcs)
            {
                double[] restrictionOutput = new double[nrOfRestrictions];
                if (nrOfRestrictions != 0)
                {
                    foreach (string restrictionID in arc.arcRestrictionIds)
                    {
                        int restrictionNr = network.restrictions.Where(a => a.id == restrictionID).First().type - 1;
                        restrictionOutput[restrictionNr] = 1.0;
                    }
                    outputList[listNr] = restrictionOutput;
                }
                else
                {
                    outputList[listNr] = restrictionOutput;
                }
                listNr++;
            }
            return(outputList);
        }
Example #2
0
        }                                                      //Nodes of the network

        //Load a Json file into one network (Network_DTO)
        public static Network_DTO LoadJson(string name)
        {
            //File path
            string jsonText = System.IO.File.ReadAllText(name);

            //Deserialize json
            Network_DTO network = JsonConvert.DeserializeObject <Network_DTO>(jsonText);

            return(network);
        }
Example #3
0
        //Input should return:
        //Sinuosity
        public static double[][] CreateInputList(Network_DTO network)
        {
            int    arcsWithCurves = 0;
            double max            = 0;
            double total          = 0;


            double[][] inputList = new double[network.arcs.Count()][];
            int        listNr    = 0;

            foreach (Arc_DTO arc in network.arcs)
            {
                double birdDist =
                    CalculateDistanceInKilometers(
                        arc.locations.First(), arc.locations.Last());
                double totalDist =
                    CalculateDistanceInKilometers(
                        arc.locations);
                double curves = 0.0;
                //If birdDist != totalDist => atleast one curve in the arc
                if (birdDist != totalDist)
                {
                    arcsWithCurves++;
                    curves = EvaluateCurves(arc.locations);
                    if (curves > max)
                    {
                        max = curves;
                    }
                    total += curves;
                }



                inputList[listNr] = new double[] { curves, 50 };
                listNr++;
            }
            Console.WriteLine("Arcs with curves: " + arcsWithCurves + " Max: " + max +
                              " Mean: " + total / network.arcs.Count());
            return(inputList);
        }
Example #4
0
        static void Main(string[] args)
        {
            //Empty variables
            Network_DTO roadNetwork = null;

            double[][]        inputList  = null;
            double[][]        outputList = null;
            ActivationNetwork ANN        = null;

            while (choice != 7)
            {
                choice = DisplayData();
                switch (choice)
                {
                case 1:
                    string[] files = Directory.GetFiles("Data/");
                    int      count = 1;
                    Console.WriteLine("Choose file: ");
                    foreach (string s in files)
                    {
                        Console.WriteLine(count + ". " + s);
                        count++;
                    }

                    roadNetwork = Network_DTO.LoadJson(files[
                                                           Convert.ToInt32(Console.ReadLine()) - 1]);

                    inputList  = Processing.CreateInputList(roadNetwork);
                    outputList = Processing.CreateOutputList(roadNetwork);

                    break;

                case 2:
                    if (roadNetwork == null)
                    {
                        Console.WriteLine("Did not load or empty network");
                        break;
                    }
                    Console.WriteLine("Learning rate?[0,0 - 1,0]");
                    double learningRate = Convert.ToDouble(Console.ReadLine());

                    ANN = NeuralNetwork.CreateANN(inputList, outputList, learningRate);
                    break;

                case 3:
                    if (ANN == null)
                    {
                        Console.WriteLine("Could not save: Neural network is null");
                        break;
                    }
                    Console.WriteLine("Give name to the neural network:");
                    string name = Console.ReadLine();
                    ANN.Save("ANN/" + name + ".json");
                    Console.WriteLine("Saved neural network");
                    break;

                case 4:
                    string[] AIs = Directory.GetFiles("ANN/");
                    count = 1;
                    Console.WriteLine("Choose file: ");
                    foreach (string s in AIs)
                    {
                        Console.WriteLine(count + ". " + s);
                        count++;
                    }
                    ANN = (ActivationNetwork)Network.Load(AIs[Convert.ToInt32(Console.ReadLine()) - 1]);
                    if (ANN == null)
                    {
                        Console.WriteLine("Could not load network");
                        break;
                    }
                    Console.WriteLine("Loaded neural network");
                    break;

                case 5:
                    if (inputList != null && ANN != null && outputList != null)
                    {
                        double[][] output = NeuralNetwork.ComputeNetwork(inputList, ANN);
                        NeuralNetwork.NetworkComparison(output, outputList);
                    }
                    if (inputList == null)
                    {
                        Console.WriteLine("Missing input");
                        break;
                    }
                    if (ANN == null)
                    {
                        Console.WriteLine("Missing ANN");
                        break;
                    }
                    if (outputList == null)
                    {
                        Console.WriteLine("Missing output");
                        break;
                    }
                    break;

                case 6:
                    Console.WriteLine("Load XML");

                    Processing.LoadXML("Data/Norrkoping_hastighet.xml");

                    break;

                case 7:
                    Console.WriteLine("Bye...");
                    break;

                case 8:     //Secret
                    //Console.WriteLine(speed.NextNode);
                    break;
                }
            }
        }