Example #1
0
 public void MergeFrom(DeciderRuleBasedStopConfig other)
 {
     if (other == null)
     {
         return;
     }
     if (other.crosswalk_ != null)
     {
         if (crosswalk_ == null)
         {
             crosswalk_ = new global::Apollo.Planning.RuleCrosswalkConfig();
         }
         Crosswalk.MergeFrom(other.Crosswalk);
     }
     if (other.stopSign_ != null)
     {
         if (stopSign_ == null)
         {
             stopSign_ = new global::Apollo.Planning.RuleStopSignConfig();
         }
         StopSign.MergeFrom(other.StopSign);
     }
     if (other.trafficLight_ != null)
     {
         if (trafficLight_ == null)
         {
             trafficLight_ = new global::Apollo.Planning.RuleTrafficLightConfig();
         }
         TrafficLight.MergeFrom(other.TrafficLight);
     }
 }
Example #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (crosswalk_ != null)
            {
                hash ^= Crosswalk.GetHashCode();
            }
            if (stopSign_ != null)
            {
                hash ^= StopSign.GetHashCode();
            }
            if (trafficLight_ != null)
            {
                hash ^= TrafficLight.GetHashCode();
            }
            return(hash);
        }
Example #3
0
    void Start()
    {
        //promjenimo x i y kako bi dobili traženi broj blokova
        x = x * 2 + 1;
        y = y * 2 + 1;
        int j     = 0;
        var graph = new Graph();

        stop          = (new GameObject("stop")).AddComponent <StopSign>();
        stop.timeLeft = stopTime;
        //  Debug.Log("Visina: " + prefabRoad.GetComponent<MeshRenderer>().bounds);

        //threeSideIntersection(0, 0, true);
        //Instantiate(RightUpSign, new Vector3((signZ), 0, 10-(signX)), Quaternion.Euler(270, 180, 0));
        //else if (i == x - 1) threeSideIntersection(i, , false);
        //postavi znakove na rubove
        twoSideIntersection(x, y);

        rnd = new System.Random(2);

        for (int i = 0; i < x; i++)
        {
            for (j = 0; j < y; j++)
            {
                //float size = prefab.GetComponent<Renderer>().bounds.size.x;
                Transform current;
                if (i % 2 != 0)
                {
                    //ovo je za prazni prostor u mreži
                    if (j % 2 != 0 && j != 0)
                    {
                        continue;
                    }

                    current = Instantiate(prefabRoad, new Vector3(i * height - additionalWidth, 0, (j * width) - additionalWidth), Quaternion.Euler(0, 0, 0));
                }
                else
                {
                    if (j % 2 != 0)
                    {
                        Transform sign;
                        current = Instantiate(prefabRoad, new Vector3((i * width), 0, (j * height)), Quaternion.Euler(0, 270, 0));
                    }
                    else
                    {
                        current = Instantiate(prefabIntersection, new Vector3((i * width), 0, (j * height)), Quaternion.Euler(0, 270, 0));
                        graph.CreateNode(i + "" + j, cnt, (((x / 2) + 1) * (y / 2 + 1)) - 1);
                        nodes.Add(current);
                        cnt++;
                    }
                }
                GameObject g = current.gameObject;
                current.name = i + "" + j;
            }
        }
        int number = Convert.ToInt32(Math.Pow(x * y, 2));

        //number = 10000;
        //  int n = number;
        //int n = Convert.ToInt32(Math.Pow(x*y, 2));

        for (int i = 0; i < graph.AllNodes.Count; i++)
        {
            //number = 2+(n /((i+1) * 2));
            //int numVal = Int32.Parse(graph.AllNodes[i].Name);
            //indexi susjdeda s lijeve i desne strane
            int numDesni  = i + (y / 2) + 1;
            int numLijevi = i - (y / 2) - 1;
            //Debug.Log(graph.AllNodes[i].Name + "  " + graph.AllNodes[i].id + " desni: " + numDesni + "  " + graph.AllNodes[i].arcsarr.Count);
            int weigth = 2;
            //prvi stupac(nemaju lijevog susjeda)
            //if (graph.AllNodes[i].id <= (x / 2))
            if (graph.AllNodes[i].id <= (y / 2))
            {
                //ako je na pocetku i nema susjeda ispod
                if (graph.AllNodes[i].id == 0)
                {
                    //weigth = rnd.Next(1,x*y );
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[1], weigth);
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[(y / 2) + 1], weigth);
                    continue;
                }
                //ako je na kraju i nema susjeda iznad
                if (graph.AllNodes[i].id == (y / 2))
                {
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[i - 1], weigth);
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[numDesni], weigth);
                    continue;
                }
                //ako je u sredini pa ima susjeda desno, gore i dole
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[i + 1], weigth);
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[i - 1], weigth);
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[numDesni], weigth);
            }
            //zadnji stupac(nema desnog susjeda)
            else if (graph.AllNodes[i].id > ((x / 2) * (y / 2) - 1) + x / 2)
            {
                //Debug.Log(graph.AllNodes[i].id + "   " + numDesni);
                //ako je u sredini pa ima susjeda desno, gore i dole
                //prvi
                if (i == ((x / 2) * (y / 2) - 1) + x / 2 + 1)
                {
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[i + 1], weigth);
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[numLijevi], weigth);
                    continue;
                }
                //zadnji
                if (i == graph.AllNodes.Count - 1)
                {
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[i - 1], weigth);
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[numLijevi], weigth);
                    continue;
                }
                //ostali
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[i + 1], weigth);
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[i - 1], weigth);
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[numLijevi], weigth);
                //Debug.Log(graph.AllNodes[i].Name + "  " + graph.AllNodes[i].id + " lijevi   : " + numLijevi + "  " + graph.AllNodes[i].arcsarr.Count);
            }
            else
            {
                //prvi u tom redu
                if ((graph.AllNodes[i].id % ((y / 2) + 1)) == 0)
                {
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[i + 1], weigth);
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[numLijevi], weigth);
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[numDesni], weigth);
                    //int b = (y / 2) + 1;
                    //Debug.Log("y: " + b + " ID: " + graph.AllNodes[i].id);
                    continue;
                }
                //zadnji u tom redu
                else if (((graph.AllNodes[i].id + 1) % ((y / 2) + 1)) == 0)
                {
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[i - 1], weigth);
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[numLijevi], weigth);
                    weigth = rnd.Next(1, number);
                    graph.AllNodes[i].AddArc(graph.AllNodes[numDesni], weigth);
                    // int b = (y / 2) + 1;
                    //Debug.Log("y: " + b + " ID: " + graph.AllNodes[i].id);
                    //povećaj random
                    //number = n;
                    continue;
                }
                // Debug.Log(graph.AllNodes[i].Name);
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[i + 1], weigth);
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[i - 1], weigth);
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[numLijevi], weigth);
                weigth = rnd.Next(1, number);
                graph.AllNodes[i].AddArc(graph.AllNodes[numDesni], weigth);
            }
        }

        //kreiranje matrice susjedstva
        int[,] adj = graph.CreateAdjMatrix();
        Graph.PrintMatrix(adj, graph.AllNodes.Count);
        //najkraći put
        path = new ShortestPath(graph.AllNodes.Count, adj, mat);
        ///postavi znakove
        signs(x, y);
        //postavi igrača
        Instantiate(player, new Vector3(0, 0, 0), Quaternion.Euler(0, 0, 0));
    }