public void Start() { left = center.x - size.x / 2; right = center.x + size.x / 2; top = center.y + size.y / 2; bottom = center.y - size.y / 2; m_BaseObstructions = new List <Collider2D>(obstructionsParent.GetComponentsInChildren <Collider2D> ()); m_Obstructions = new List <Collider2D> (m_BaseObstructions); SetupPoints(); if (initialRoad != null) { Vector3[] lineRendererPositions = new Vector3[initialRoad.positionCount]; initialRoad.GetPositions(lineRendererPositions); initVertices = new Vector2[lineRendererPositions.Length]; for (int i = 0; i < initVertices.Length; i++) { initVertices [i] = lineRendererPositions [i]; } } GridPoint[] initPoints = new GridPoint[initVertices.Length]; for (int i = 0; i < initPoints.Length; i++) { initPoints [i] = ConvertToGridPoint(initVertices [i]); } CityGraph init = new CityGraph(initPoints, connectVerts: true); m_LastIterations = iterations; StartCoroutine(GenerateCity(init, iterations, generations, increment)); }
void Start() { Physics.queriesHitTriggers = true; firstClicked = true; cities = GameObject.Find("Cities"); if (cities == null) { Debug.Log("Can't find Cities!?!"); } cg = cities.GetComponent <CityGraph>(); if (cg == null) { Debug.Log("Can't find citygraph!?!"); } pawns = GameObject.Find("Pawns").GetComponent <Players>(); if (pawns == null) { Debug.Log("Can't find Pawns"); } infectDec = GameObject.Find("infectDec").GetComponent <InfectDeck>(); if (infectDec == null) { Debug.Log("Can't find infectDec"); } }
public TSPSolver(CityGraph graph) { this.cityGraph = graph; this.cityDistances = new Dictionary <string, double>(); this.cityVisited = new Dictionary <string, bool>(); this.solverResult = new SolverResult(); }
private void GraphForm_Load(object sender, EventArgs e) { graph = new CityGraph(); GraphDraw = new GraphDraw(Image.Size, graph); Oper.SelectedIndex = 0; NodeOrEdge.SelectedIndex = 0; }
public void Update() { if (drawGraph && m_Graph != null) { Debug.DrawLine(new Vector2(left, top), new Vector2(right, top), Color.blue); Debug.DrawLine(new Vector2(right, top), new Vector2(right, bottom), Color.blue); Debug.DrawLine(new Vector2(right, bottom), new Vector2(left, bottom), Color.blue); Debug.DrawLine(new Vector2(left, bottom), new Vector2(left, top), Color.blue); CityGraph.Edge[] graphEdges = m_Graph.GetEdges(); for (int i = 0; i < graphEdges.Length; i++) { Debug.DrawLine( graphEdges[i].pointA.position.ConvertToWorldPoint(m_PointSpacing), graphEdges [i].pointB.position.ConvertToWorldPoint(m_PointSpacing), Color.red); } } if (iterations > m_LastIterations) { int newIterations = iterations - m_LastIterations; m_LastIterations = iterations; m_Graph = BuildRRT(m_Graph, newIterations, increment); } }
void Awake() { cityGraph = GameObject.Find("CityGraph").GetComponent <CityGraph>(); agentsManager = GameObject.Find("GameManager").GetComponent <AgentsManager>(); agentsManager.allWalker.Add(this); myRend = gameObject.GetComponentInChildren <Renderer>(); blood = transform.GetComponentInChildren <ParticleSystem>(); }
private CityGraph AddBuildingsToCity(CityGraph currentCity, int lotsToPlace) { //Sort Edges by distance from the center in travel time. List <CityGraph.Edge> allEdges = new List <CityGraph.Edge>(currentCity.GetEdges()); allEdges.Sort(CompareEdges); //place lots on edges (left or right) //Lots are made up of at least 4 points. float totalLotsToPlace = lotsToPlace; for (int i = 0; i < allEdges.Count && lotsToPlace > 0; i++) { if (Random.value < (1 - populationDensity)) { continue; } if (allEdges [i].NeighbouringLotsCount < 2) { GridPoint point1 = allEdges [i].pointA.position; GridPoint point2 = allEdges [i].pointB.position; Vector2 point1Vec = point1.ConvertToWorldPoint(m_PointSpacing); Vector2 point2Vec = point2.ConvertToWorldPoint(m_PointSpacing); Vector2 edgeVector = point2Vec - point1Vec; Vector2 rhNormal = new Vector2(edgeVector.y, -edgeVector.x); Vector2 lhNormal = new Vector2(-edgeVector.y, edgeVector.x); CityGraph.Lot rhLot = new CityGraph.Lot(point1, point2, ConvertToGridPoint(point1Vec + rhNormal), ConvertToGridPoint(point2Vec + rhNormal)); CityGraph.Lot lhLot = new CityGraph.Lot(point1, point2, ConvertToGridPoint(point1Vec + lhNormal), ConvertToGridPoint(point2Vec + lhNormal)); bool coinFlip = Random.value > 0.5f; CityGraph.Lot lotToAdd = rhLot; if (coinFlip == true) { lotToAdd = lhLot; } bool success = currentCity.AddLot(allEdges [i], lotToAdd); if (!success) { lotToAdd = coinFlip ? rhLot : lhLot; success = currentCity.AddLot(allEdges [i], lotToAdd); } if (success) { lotsToPlace--; } } } return(currentCity); }
public List <Collider2D> DrawRoads(CityGraph graph, float pointSpacing) { ClearLastObjects(); List <Collider2D> newObstructions = new List <Collider2D> (); CityGraph.Edge[] graphEdges = graph.GetEdges(); for (int i = 0; i < graphEdges.Length; i++) { GameObject segment = Instantiate <GameObject> (roadSegment); m_Roads.Add(segment); LineRenderer segmentRederer = segment.GetComponent <LineRenderer> (); Vector3[] positions = new Vector3[2]; positions [0] = graphEdges [i].pointA.position.ConvertToWorldPoint(pointSpacing); positions [1] = graphEdges [i].pointB.position.ConvertToWorldPoint(pointSpacing); segmentRederer.SetPositions(positions); segmentRederer.widthMultiplier *= Mathf.Min(Vector3.Distance(positions [0], positions [1]), 2); } CityGraph.Lot[] lots = graph.GetLots(); for (int i = 0; i < lots.Length; i++) { GameObject building = Instantiate <GameObject> (buildingPrefab); m_Buildings.Add(building); Vector2 upVector = lots [i].corners [1].ConvertToWorldPoint(pointSpacing) - lots [i].corners [0].ConvertToWorldPoint(pointSpacing); Vector2 rightVector = lots [i].corners [2].ConvertToWorldPoint(pointSpacing) - lots [i].corners [1].ConvertToWorldPoint(pointSpacing); float width = Mathf.Min(maxBuildingWidth, rightVector.magnitude) * 0.9f; float depth = Mathf.Min(maxBuildingDepth, upVector.magnitude) * 0.9f; float height = (width + depth) / 2; building.transform.localScale = new Vector3(depth, width, height); float x = Vector2.Dot(rightVector, Vector2.right); float y = Vector2.Dot(rightVector, Vector2.up); float angle = Mathf.Rad2Deg * Mathf.Acos(x / Mathf.Max(rightVector.magnitude, 0.01f)); if (y < 0) { angle *= -1; } building.transform.localEulerAngles = new Vector3(0, 0, angle); Vector3 position = (Vector3)lots [i].GetCenter(pointSpacing); position.z = -height / 2; building.transform.localPosition = position; newObstructions.Add(building.GetComponent <Collider2D> ()); } return(newObstructions); }
private void OpenBtn_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { try { FileWork file = new FileWork(openFileDialog.FileName); graph = file.Read(); GraphDraw.graph = graph; UpdateImage(); } catch (Exception) { MessageBox.Show("Error"); } } }
public AcoSolver(CityGraph cities, int noOfAnts, int noOfIteration) : base(cities) { this.noOfAnts = noOfAnts; this.noOfIteration = noOfIteration; this.betaCoffiecient = 1; this.evaporationConstant = 0.5; this.stagnationCoffiecient = 100; this.processedMilestones = 0; useSequenceAntDistribution = 0; this.antVisitedCities = new Dictionary <int, List <CityResult> >(); this.pheromoneAmountPerArc = new Dictionary <string, double>(); this.phermoneLock = new object(); this.randomizer = new Random(); }
private GridPoint GetNearestPoint(Vector2 point, CityGraph graph) { float lowest = float.MaxValue; int nearestIndex = -1; for (int i = 0; i < graph.GetVertexCount(); i++) { float curDist = Vector2.Distance(graph.GetVertexAt(i).position.ConvertToWorldPoint(m_PointSpacing), point); if (curDist < lowest) { lowest = curDist; nearestIndex = i; } } return(graph.GetVertexAt(nearestIndex).position); }
/// <summary> /// Load cities from file /// </summary> private void LoadCityGraph() { if (this.filename != string.Empty) { this.cityGraph = new CityGraph(this.filename, this.Canvas.Width, this.Canvas.Height); if (this.cityGraph.Cities != null) { this.dimension = this.cityGraph.Cities.Count; this.labelDimension.Text = Convert.ToString(this.dimension); this.labelTourLen.Text = string.Empty; this.labelTime.Text = string.Empty; } this.DrawCityOnCanvas(); this.labelfileName.Text = string.Format("Data Loaded from : {0}", this.GetShortenFilename()); } }
// Use this for initialization void Start() { cities = GameObject.Find("Cities"); if (cities == null) { Debug.Log("Can't find Cities!?!"); } cg = cities.GetComponent <CityGraph>(); if (cg == null) { Debug.Log("Can't find citygraph!?!"); } #if false infectDec = GameObject.Find("infectDec").GetComponent <InfectDeck>(); if (infectDec == null) { Debug.Log("Can't find infectDec"); } #endif }
// Use this for initialization void Start() { instance = this; print("Initialize game"); graph = GetComponent <CityGraph> (); powerplantShop = GameObject.FindObjectOfType <PowerPlantShop> (); //setup players players = new ArrayList(); playerOrderPieces = new ArrayList(); playerOrderPieces.Add(GameObject.Find("PlayerOrderPiece1")); playerOrderPieces.Add(GameObject.Find("PlayerOrderPiece2")); playerOrderPieces.Add(GameObject.Find("PlayerOrderPiece3")); playerOrderPieces.Add(GameObject.Find("PlayerOrderPiece4")); //create objects from GUI setup Player[] p = FindObjectsOfType(typeof(Player)) as Player[]; for (int i = 0; i < p.Length; i++) { players.Add(p [i]); ((GameObject)playerOrderPieces[i]).GetComponent <Renderer>().material.color = p[i].color; } players.Sort(); players.Reverse(); //create material store materialStore = new PowerPlantMaterialStore(); InitializePayoutTable(); // InitializePowerPlants (); // DealCards (); // // ShufflePowerPlantCards (); }
void Start() { //add all pawns to list foreach (Transform tchild in transform) { pawns.Add(tchild.gameObject); } var tp = GameObject.Find("textPlayers"); if (tp == null) { Debug.Log("textPlayers not found!"); } textPlayers = tp.GetComponent <TextMeshPro>(); var cities = GameObject.Find("Cities"); if (cities == null) { Debug.Log("cities not found"); } cg = cities.GetComponent <CityGraph>(); }
private CityGraph BuildRRT(CityGraph init, int numVerticesK, float incDist) { CityGraph outputGraph = init; RemoveObstructedPoints(); if (restrictToCircle) { } for (int k = 0; k < numVerticesK; k++) { Vector2 qRand = GetRandomPoint(); GridPoint qNear = GetNearestPoint(qRand, init); float curInc = incDist - ((outputGraph.GetVertexCount() / reduceIncEvery) * reduceBy); curInc = Mathf.Max(curInc, minIncrement); GridPoint qNew = NewConfig(qNear.ConvertToWorldPoint(m_PointSpacing), qRand, curInc); outputGraph.AddVertex(qNew); outputGraph.AddEdge(qNear, qNew); } return(outputGraph); }
private IEnumerator GenerateCity(CityGraph init, int iterationsPerStep, int generations, float baseRoadIncrement) { //Each generation iteration is // 1. [FIND PATHS] find paths in current area with destinations in mind // 2. [PLACE BUILDINGS] place buildings of varying size based on distance to city 'centres' // 3. [SIMULATE TRAVEL] simulate trips from sources (dwellings & outer roads) to destinations (all points of interest including dwellings and outer roads) // 4. [PLACE ROADS] tally the number of times an edge is used in a path to destinations, discard edges that are not used in trips, the rest become roads. Base road width on path usage. // 5. Repeat with the current graph as the initial state and buildings as obstructions m_Graph = init; for (int i = 0; i < generations; i++) { //1. FIND PATHS m_Graph = BuildRRT(m_Graph, iterationsPerStep, baseRoadIncrement); //2. PLACE BUILDINGS m_Graph = AddBuildingsToCity(m_Graph, populationPerGeneration * (i + 1)); //3. SIMULATE TRAVEL //4. PLACE ROADS m_Obstructions = new List <Collider2D> (m_BaseObstructions); m_Obstructions.AddRange(cityRenderer.DrawRoads(m_Graph, m_PointSpacing)); yield return(null); } }
// Use this for initialization void Start() { instance = this; print ("Initialize game"); graph = GetComponent<CityGraph> (); powerplantShop = GameObject.FindObjectOfType<PowerPlantShop> (); //setup players players = new ArrayList(); playerOrderPieces = new ArrayList (); playerOrderPieces.Add (GameObject.Find("PlayerOrderPiece1")); playerOrderPieces.Add (GameObject.Find("PlayerOrderPiece2")); playerOrderPieces.Add (GameObject.Find("PlayerOrderPiece3")); playerOrderPieces.Add (GameObject.Find("PlayerOrderPiece4")); //create objects from GUI setup Player[] p = FindObjectsOfType(typeof(Player)) as Player[]; for (int i = 0; i < p.Length; i++) { players.Add (p [i]); ((GameObject)playerOrderPieces[i]).GetComponent<Renderer>().material.color = p[i].color; } players.Sort (); players.Reverse (); //create material store materialStore = new PowerPlantMaterialStore (); InitializePayoutTable (); // InitializePowerPlants (); // DealCards (); // // ShufflePowerPlantCards (); }
void Start() { cityGraph = GameObject.Find("CityGraph").GetComponent <CityGraph>(); carsParent = GameObject.Find("Cars").transform; walkersParent = GameObject.Find("Walkers").transform; }
public GreedySolver(CityGraph cities) : base(cities) { }