private static void CollectLines() { int lid = 0; foreach (SubwayLine sl in subwayMap.Lines) { LineStations.Add(new List <int>()); LineId[sl.Name] = lid; int lastStationId = -1; foreach (string stationName in sl.Path) { int sid = StationId[stationName]; LineStations[lid].Add(sid); if (!StationLines[sid].Contains(lid)) { StationLines[sid].Add(lid); } if (lastStationId != -1) { RouteSet.Add(new Tuple <int, int>(lastStationId, sid)); RouteSet.Add(new Tuple <int, int>(sid, lastStationId)); } lastStationId = sid; } lid++; } }
public List <Tuple <int, double> > GetDualVariables(string folderPath, RouteSet solution) { /*Solo permite obtener soluciones extremales del dual que son muy malas para la generacion de columnas*/ ColumnSelectionGAMS gamsProcedure = new ColumnSelectionGAMS(ProblemData); return(gamsProcedure.DualSolve(folderPath, GetExtRouteInfo(solution))); }
private void InitCollections() { _unitGroups = new UnitGroupSet(this); _packages = new PackageSet(this); _routes = new RouteSet <Shape>(this); _products = new ProductSet <Shape>(this); }
protected RouteSet HeuristicCGSolve <TProcedure, TParameters>(List <RouteSet> pool, Exploration expCondition, double overloadFactor, Random rdObj, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods, List <Func <RouteSet, Random, RouteSet> > shaking, TProcedure procedure, TParameters parameters, string folderPath, int maxIterations, bool includedDualInfo, bool useCompletePool, bool parallelexe) where TProcedure : LocalSearchProcedure <RouteSet, TParameters> { RouteSet bestSolution = (RouteSet)pool[0].Clone(); double bestCost = GetCost(bestSolution); for (int i = 0; i < pool.Count; i++) { DirectoryInfo iterationDir = Directory.CreateDirectory(folderPath).CreateSubdirectory(string.Format("mcg{0}", i)); RouteSet current = HeuristicCGSolve(pool[i], expCondition, overloadFactor, rdObj, neighborhoods, shaking, procedure, parameters, iterationDir.FullName, maxIterations, includedDualInfo, useCompletePool, parallelexe); double currentCost = GetCost(current); if (currentCost < bestCost) { bestCost = currentCost; bestSolution = (RouteSet)current.Clone(); OnIteration(new IterationEventArgs <RouteSet>(bestSolution)); } } return(bestSolution); }
protected RouteSet ParseWeakSolution(StreamReader weakSolution) { RouteSet weakRS = RouteSet.BuildEmptyRouteSet(ProblemData.Vehicles); Regex routeExp = new Regex(@"(?<c>C\d+)\S+(?<v>V\d+)\S+(?<a>\d\.d+)"); while (!weakSolution.EndOfStream) { string line = weakSolution.ReadLine(); if (line == "") { break; } //Match mline = routeExp.Match(line); int c_index = line.IndexOf('C'); int c_sep = line.IndexOf(' ', c_index); int c = int.Parse(line.Substring(c_index + 1, c_sep - c_index - 1)); int v_index = line.IndexOf('V'); int v_sep = line.IndexOf(' ', v_index); int v = int.Parse(line.Substring(v_index + 1, v_sep - v_index - 1)); int dot_index = line.IndexOf('.'); int val = int.Parse(line.Substring(dot_index - 1, 1)); if (val != 0) { weakRS[v - 1].Add(c); } } weakSolution.Close(); return(weakRS); }
/* * private void FindWayToRoute() * { * if (temp != null) * RouteSetWP.RemoveRoute(temp); * * Road from = ExtractRoadFrom(WorldMap.GetTile(Position)); * WayPoint fromWP = from.WPContainer.GetClosestWP(Position); * * if (Vector3.Dot(Position + transform.right, transform.InverseTransformPoint(fromWP.Position)) < 0) * fromWP = from.WPContainer.GetClosestWPExcept(Position, fromWP); * * temp = new RouteWP(RouteCreator.CreatePathToRouteWP(prev, route, route_forward), true); * * if (temp == null) { Abort("Path does not exist"); return; } * * if (!route.Contains(temp[temp.Count - 1])) * { * Debug.Log("<color=red>WTF temp route does not lead to main route</color>\nTrying to recalculate..."); * * temp = new RouteWP(RouteCreator.CreatePathToRouteWP(fromWP, route, route_forward), true); * * if (!route.Contains(temp[temp.Count - 1])) * Debug.Log("<color=red>RECALCULATION FAILED</color>"); * } * * RouteSetWP.AddRoute(temp, false); * * on_main_route = false; * current_WP = 0; * * if (sphereCurr == null) * throw new System.NullReferenceException("sphereCurr"); * * sphereCurr.SetPosition(fromWP.Position); * * temp.HighLight(true, Color.red); * } */ private void FindWayToRoute() { List <WayPoint> newTemp = RouteCreator.CreatePathWP(current, route_forward ? route.endWP : route.startWP, false); if (newTemp == null) { Abort("Path does not exist"); return; } if (temp != null) { RouteSet.RemoveRoute(temp); } temp = new Route(newTemp, true); RouteSet.AddRoute(temp, false); on_main_route = false; current_WP = 0; sphereCurr.SetPosition(current.Position); Road curr = ExtractRoadFrom(WorldMap.GetTile(Position)); tempRoad = GetBack.GetWayToClosest(curr, mainRoad); for (int i = 0; i < tempRoad.Count; i++) { tempRoad[i].SetColor(RoadColor.Red); } //enabled = false; }
/// <summary> /// Exports a RouteSet to an frt file. /// </summary> /// <param name="routeSet">The RouteSet to export.</param> /// <param name="hashManager">Hash manager instance.</param> /// <param name="exportPath">File path to export to.</param> public static void ExportRouteSet(RouteSet routeSet, StrCode32HashManager hashManager, string exportPath) { Assert.IsNotNull(routeSet, "RouteSet must not be null."); Assert.IsNotNull(hashManager, "hashManager must not be null."); Assert.IsNotNull(exportPath, "exportPath must not be null."); Assert.IsNotNull(routeSet.Routes, "RouteSet.Routes must not be null."); var routeCount = routeSet.Routes.Count; Assert.IsTrue(routeCount > 0, "Invalid route count. Cannot write a routeset with no routes."); Assert.IsTrue(routeCount <= ushort.MaxValue, "Invalid route count. Only up to " + ushort.MaxValue + " routes can be written to file."); EventFactory.GetNodeEventTypeHashDelegate hashNodeEventType = (@event) => GetEventTypeHash(@event, hashManager); EventFactory.GetEdgeEventTypeHashDelegate hashEdgeEventType = (@event) => GetEventTypeHash(@event, hashManager); RouteFactory.GetRouteNameHashDelegate hashRouteName = (route) => GetRouteNameHash(route, hashManager); var eventDictionary = new Dictionary <RouteEvent, FoxLib.Tpp.RouteSet.RouteEvent>(); NodeFactory.TryGetEventInstanceDelegate getEventInstance = eventDictionary.TryGetValue; NodeFactory.RegisterEventInstanceDelegate registerEventInstance = eventDictionary.Add; var eventBuilder = EventFactory.CreateFactory(hashNodeEventType, hashEdgeEventType); var nodeBuilder = NodeFactory.CreateFactory(getEventInstance, registerEventInstance, eventBuilder); var routeBuilder = RouteFactory.CreateFactory(nodeBuilder, hashRouteName); var routeSetBuilder = RouteSetFactory.CreateFactory(routeBuilder); var outgoingRouteSet = routeSetBuilder(routeSet); using (var writer = new BinaryWriter(new FileStream(exportPath, FileMode.Create), FoxLib.Tpp.RouteSet.getEncoding())) { Action <int> writeEmptyBytes = numberOfBytes => WriteEmptyBytes(writer, numberOfBytes); var writeFunctions = new FoxLib.Tpp.RouteSet.WriteFunctions(writer.Write, writer.Write, writer.Write, writer.Write, writer.Write, writeEmptyBytes); FoxLib.Tpp.RouteSet.Write(writeFunctions, outgoingRouteSet); } }
private void DrawToolShelf(RouteSet routeset) { var iconAddRoute = Resources.Load("UI/Route Builder/Buttons/routebuilder_button_route") as Texture; var iconExport = Resources.Load("UI/Route Builder/Buttons/routebuilder_button_export") as Texture; Rotorz.Games.Collections.ReorderableListGUI.Title("Tools"); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Add route button if (FoxKitUiUtils.ToolButton(iconAddRoute, "Add a new route.")) { routeset.AddNewRoute(); } // Export button if (FoxKitUiUtils.ToolButton(iconExport, "Export to .frt file.")) { var exportPath = EditorUtility.SaveFilePanel( "Export frt", string.Empty, routeset.name + ".frt", "frt"); if (string.IsNullOrEmpty(exportPath)) { return; } var hashManager = new StrCode32HashManager(); RouteSetExporter.ExportRouteSet(routeset, hashManager, exportPath); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
void Start() { GameObjects = this; WorldMap.Initialize(); StartCoroutine(RouteSet.CheckRoutes()); }
public RouteSet RdVNDBasicPenalization(RouteSet initial, Exploration expCondition, Random rdObj, double overloadFactor, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods) { OverloadFactor = overloadFactor; RandomVariableNeighborhoodDescentProcedure <RouteSet> vndProcedure = new RandomVariableNeighborhoodDescentProcedure <RouteSet>(); return(vndProcedure.Solve(initial, neighborhoods, expCondition, GetCost, rdObj)); }
public ApplicationRouteSetMap CreateInstance(Service service, RouteSet routeSet) { if (!this.HasData) { return(null); } return(new ApplicationRouteSetMap(this.ApplicationRouteSetMapID, new Application(this.ApplicationID), service ?? (this.ServiceID.HasValue ? new Service(this.ServiceID.Value) : null), routeSet ?? new RouteSet(this.RouteSetID), this.Updated, this.Created)); }
/// <summary> /// Deletes the RouteSet /// </summary> /// <param name="route"> The RouteSet to be deleted</param> /// <returns>true, if deletion was sucessfull, false otherwise</returns> public static bool DeleteRouteSet(RouteSet routeSet) { if (routeSet != null) { return(dataAccess.DeleteItem <RouteSet> (routeSet.Id)); } return(true); }
public RouteSet BasicPenalization(RouteSet initial, Exploration expCondition, Random rdObj, double overloadFactor, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods, double saProbability, double saWorst, int saRepetitions, double saFactor, double saCoolingRate, int saCoolerAmount) { SimulatedAnnealingParameters saParameters = new SimulatedAnnealingParameters(GetCost(initial), saProbability, saWorst, saRepetitions, saFactor, saCoolingRate, saCoolerAmount); return(BasicPenalization(initial, expCondition, rdObj, overloadFactor, neighborhoods, saParameters)); }
public List <Route> Load(ISqlConnectionInfo connection, RouteSet routeSet) { SqlQueryParameters parameters = new SqlQueryParameters(); parameters.Where = "[r].RouteSetID=@RouteSetID"; parameters.Arguments.Add("RouteSetID", routeSet.ID); return(this.LoadMany(connection, parameters)); }
public Route CreateInstance(RouteSet routeSet) { if (!this.HasData) { return(null); } return(new Route(this.RouteID, routeSet ?? new RouteSet(this.RouteSetID), this.Name, this.Action, this.Controller, this.Pattern, this.IsIgnore, this.IsEnabled, this.Index, this.IsSessionRoute, this.Updated, this.Created)); }
public RouteSet ParallelExeRdVNDParallelShakingPenalization(RouteSet initial, int reStarts, Exploration expCondition, Random rdObj, double overloadFactor, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods, List <Func <RouteSet, Random, RouteSet> > shaking) { RandomVariableNeighborhoodDescentProcedure <RouteSet> vndProcedure = new RandomVariableNeighborhoodDescentProcedure <RouteSet>(); return(ParallelShakingPenalization(initial, reStarts, expCondition, rdObj, overloadFactor, neighborhoods, shaking, vndProcedure, new NullParameters(), true)); }
public RouteSet BasicPenalization(RouteSet initial, Exploration expCondition, Random rdObj, double overloadFactor, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods, SimulatedAnnealingParameters saParameters) { OverloadFactor = overloadFactor; SimulatedAnnealingProcedure <RouteSet> saProcedure = new SimulatedAnnealingProcedure <RouteSet>(); return(saProcedure.Solve(saParameters, initial, neighborhoods, expCondition, GetCost, rdObj)); }
/// <summary> /// Create a RouteSet. /// </summary> /// <param name="data">Parameters of the RouteSet to construct.</param> /// <param name="createRoute">Function to create a Route.</param> /// <returns>The constructed RouteSet.</returns> private static FoxLib.Tpp.RouteSet.RouteSet Create(RouteSet data, CreateRouteDelegate createRoute) { var routes = from route in data.Routes select createRoute(route); var routeset = new FoxLib.Tpp.RouteSet.RouteSet(routes.ToArray()); return(routeset); }
/// <summary> /// Writes a RouteSet to a .frt file. /// </summary> /// <param name="routeset">RouteSet to write.</param> /// <param name="outputPath">Path of the file to write.</param> public static void WriteRouteSet(RouteSet routeset, string outputPath) { using (var writer = new BinaryWriter(new FileStream(outputPath, FileMode.Create), getEncoding())) { Action <int> writeEmptyBytes = numberOfBytes => WriteEmptyBytes(writer, numberOfBytes); var writeFunctions = new WriteFunctions(writer.Write, writer.Write, writer.Write, writer.Write, writer.Write, writeEmptyBytes); Write(writeFunctions, routeset); } }
public RouteSet ParallelShakingPenalization(RouteSet initial, int reStarts, Exploration expCondition, Random rdObj, double overloadFactor, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods, List <Func <RouteSet, Random, RouteSet> > shaking, SimulatedAnnealingParameters saParameters) { SimulatedAnnealingProcedure <RouteSet> saProcedure = new SimulatedAnnealingProcedure <RouteSet>(); return(ParallelShakingPenalization(initial, reStarts, expCondition, rdObj, overloadFactor, neighborhoods, shaking, saProcedure, saParameters, false)); }
public RouteSet ParallelExeRdVNDHeuristicCGSolve(RouteSet initial, Exploration expCondition, double overloadFactor, Random rdObj, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods, List <Func <RouteSet, Random, RouteSet> > shaking, string folderPath, int maxIterations, bool completePool, bool dualInfo) { RandomVariableNeighborhoodDescentProcedure <RouteSet> procedure = new RandomVariableNeighborhoodDescentProcedure <RouteSet>(); return(HeuristicCGSolve(initial, expCondition, overloadFactor, rdObj, neighborhoods, shaking, procedure, new NullParameters(), folderPath, maxIterations, dualInfo, completePool, true)); }
private List <ExtRouteInfo> GetExtRouteInfo(RouteSet solution) { List <ExtRouteInfo> info = new List <ExtRouteInfo>(); foreach (var r in solution) { info.Add(new ExtRouteInfo(r, GetTravelCost(r))); } return(info); }
private List <Tuple <Route, double> > GetInitialCoveringSelection(RouteSet initial) { List <Tuple <Route, double> > masterProblem = new List <Tuple <Route, double> >(); foreach (var r in initial) { masterProblem.Add(new Tuple <Route, double>(r, 1)); } return(masterProblem); }
public List <ExtRouteInfo> GetInitialPool(RouteSet initial) { List <ExtRouteInfo> pool = new List <ExtRouteInfo>(); foreach (var item in initial) { pool.Add(new ExtRouteInfo(item, GetCost(item))); } return(pool); }
public RouteSet OrderByLoadDifference(RouteSet solution) { RouteSet newSolution = (RouteSet)solution.Clone(); for (int i = 0; i < newSolution.Count; i++) { newSolution[i] = OrderByLoadDifference(newSolution[i]); } return(newSolution); }
private List <ExtRouteInfo> BuildRestrictedPool <TProcedure, TParameters>(RouteSet initial, Exploration expCondition, Random rdObj, List <Func <RouteSet, Exploration, Random, RouteSet> > neighborhoods, List <Func <RouteSet, Random, RouteSet> > shaking, int iteration, Stopwatch timer, TProcedure procedure, TParameters parameters, bool parallelexe) where TProcedure : LocalSearchProcedure <RouteSet, TParameters> { List <Tuple <RouteSet, double> > shkPool = (parallelexe)?ParallelExeParallelShaking(expCondition, rdObj, neighborhoods, shaking, procedure, parameters, initial, initial, iteration, timer): ParallelShaking(expCondition, rdObj, neighborhoods, shaking, procedure, parameters, initial, initial, iteration, timer); return(BuildRestrictedPool(shkPool)); }
private IEnumerator ReDrawRoutes() { while (true) { RouteSet.HighLightAll(false); GizmosDrawer.Clear(); RouteSet.HighLightAll(true); yield return(new WaitForSeconds(2)); } }
private void btnRouteSet_Click(object sender, RoutedEventArgs e) { RouteSetModeSelectDialog routeSetModeSelect = new RouteSetModeSelectDialog(); bool dialogResult = routeSetModeSelect.ShowDialog().GetValueOrDefault(false); if (dialogResult) { RouteSet routeSetPage = new RouteSet(routeSetModeSelect.ClimbModeSelected); ParentPage.NavigationService.Navigate(routeSetPage); } }
public List <Route> Load(IConnectionInfo connection, RouteSet routeSet) { ISqlConnectionInfo sqlConnection = connection as ISqlConnectionInfo; if (sqlConnection != null) { return(this.Load(sqlConnection, routeSet)); } using (sqlConnection = new SqlConnectionInfo(connection, this.Type)) return(this.Load(sqlConnection, routeSet)); }
public double LowerBound(string folderPath, RouteSet solution, double capacity, int maxESPPRCTime) { double[] dualVars = GetDualVariables(solution); double[,] reducedEdges = GetReducedCostEdges(dualVars); List <Route> negativeCostRoutes = ElementaryShortestPathResourceConstraints(reducedEdges, capacity, maxESPPRCTime); List <Route> newFounded = NewRouteFounded(solution, negativeCostRoutes); List <ExtRouteInfo> currentPool = BuildCoveringPool(solution, newFounded); List <Tuple <Route, double> > coveringSelection = SolveRestrictedMasterProblem(folderPath, "coveringPool", currentPool); return(coveringSelection.Sum(r => GetCost(r.Item1) * r.Item2)); }