Пример #1
0
        static void Main(string[] args)
        {
            string[]   lines    = File.ReadAllLines("C:\\Users\\igork\\source\\repos\\TLD\\TLD\\tests.txt");
            string[]   _density = lines[1].Split(",");
            List <int> _den     = new List <int>();

            foreach (string d in _density)
            {
                _den.Add(int.Parse(d));
            }
            Junction    jn   = new Junction(int.Parse(lines[0]), _den.ToArray());
            Constraints cons = new Constraints(int.Parse(lines[0]));

            string[] temp = lines[2].Split("|");
            foreach (string s in temp)
            {
                string[] p = s.Split(",");
                cons.Add_cons(int.Parse(p[0]), int.Parse(p[1]));
            }
            jn = SimulatedAnnealing.Compute(jn, 20f, 0.000001f, 50);
            // Console.WriteLine(tools.DeepToString(_den.ToArray()));
            Console.WriteLine(jn);
            //for(int i = 0; i < jn.getOrder().Length; i++) {
            //    Console.Write(" " + jn.getOrder()[i]);
            //}
        }
Пример #2
0
    /// <summary>
    /// Compute traffic lights cycle's order, MUST HAVE CONSTRAINTS IN PLACE!
    /// sends to the result adapter the results
    /// </summary>
    /// <param name="_nor"> Number of elements (roads or traffic lights) </param>
    /// <param name="_density"> Density of each element as list : (road number 1, density(0)),.... </param>
    /// <returns> Open order for elements based on constraints. each row represent cycles segment,
    /// each column represents number of element to open. </returns>
    public void AlgoRun(int _nor, List <int> _density)
    {
        cycleTime = numOfRoads * timeForCycle;
        Constraints _cons = new Constraints(_nor);

        foreach (string s in constraintList)
        {
            string[] temp = s.Split(',');
            _cons.Add_cons(int.Parse(temp[0]), int.Parse(temp[1]));
        }
        Junction _jn     = new Junction(_nor, _density.ToArray());
        Junction _result = SimulatedAnnealing.Compute(_jn, 20, 0.00001f, 3500);

        Debug.Log(_result);
        resultAdapter.GetComponent <resultAdapter>().schedule(_result, cycleTime);
    }