/// <summary> /// Validate given solution /// </summary> /// <param name="tour">Tour to check</param> private void ValidateTour(ITour tour) { if (tour == null) { throw new ArgumentNullException("tour"); } if (tour.Dimension != tour.Nodes.Count) { throw new TourInvalidException("Tour dimension does not match number of nodes on a list"); } HashSet <int> identifiers = new HashSet <int>(); foreach (int nodeId in tour.Nodes) { if (identifiers.Contains(nodeId)) { throw new TourInvalidException("Tour is invalid, has a node " + nodeId + " multiple times"); } if (null == NodeProvider.GetNode(nodeId)) { throw new TourInvalidException("Tour is invalid, has a node " + nodeId + " which is not present in a problem"); } identifiers.Add(nodeId); } }
public TourWrapper(ITour subtour, ITourWrapper tourWrapper, int purpose, bool suppressRandomVOT) { _tour = subtour; _exporter = Global .ContainerDaySim .GetInstance <IPersistenceFactory <ITour> >() .Exporter; _tourCreator = Global .ContainerDaySim .GetInstance <IWrapperFactory <ITourCreator> >() .Creator; // relations properties Household = tourWrapper.Household; Person = tourWrapper.Person; PersonDay = tourWrapper.PersonDay; ParentTour = tourWrapper; SetParcelRelationships(subtour); // flags/choice model/etc. properties SetValueOfTimeCoefficients(purpose, suppressRandomVOT); }
/// <summary> /// évenement /// </summary> /// <param name="tour">prévenir les spectateurs qu'un tour ient d'être exécuter. on passe le tour en argument d'évenement. Le spectateur réagira à cet évenement</param> protected virtual void OnApplauseRequested(ITour tour) { if (ApplauseRequested != null) { ApplauseRequested(this, new ApplaudirEventArgs(tour)); } }
// TODO: no opt tours for SOP, VRP, ATSP with known distance for validation private static void AssertTourDistance(FileType problemType, string problemFileName, string tourFileName, int expectedDistance) { var problemTspFile = Path.Combine(RootDir, problemFileName); var tourTspFile = TspFile.Load(Path.Combine(RootDir, tourFileName)); Assert.IsNotNull(problemTspFile); Assert.IsNotNull(tourTspFile); IProblem problem = null; switch (problemType) { case FileType.TSP: case FileType.ATSP: problem = TravelingSalesmanProblem.FromFile(problemTspFile); break; case FileType.CVRP: problem = CapacitatedVehicleRoutingProblem.FromFile(problemTspFile); break; case FileType.SOP: problem = SequentialOrderingProblem.FromFile(problemTspFile); break; } Assert.IsNotNull(problem); ITour tour = Tour.FromTspFile(tourTspFile); Assert.IsNotNull(tour); Assert.AreEqual(expectedDistance, problem.TourDistance(tour)); }
private static TWrapper CreateWrapper(ITour tour, IPersonDayWrapper personDayWrapper, int purpose, bool suppressRandomVOT) { Type type = typeof(TWrapper); object instance = Activator.CreateInstance(type, tour, personDayWrapper, purpose, suppressRandomVOT); return((TWrapper)instance); }
void CacheTour(ITour tour) { if (!cachedTours.ContainsKey(tour.FileName)) { cachedTours.Add(tour.FileName, tour); } }
private static TWrapper CreateWrapper(ITour subtour, ITourWrapper tourWrapper, int purpose, bool suppressRandomVOT) { var type = typeof(TWrapper); var instance = Activator.CreateInstance(type, subtour, tourWrapper, purpose, suppressRandomVOT); return((TWrapper)instance); }
public TourWrapper(ITour tour, IPersonWrapper personWrapper, IPersonDayWrapper personDayWrapper, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int destinationPurpose) { _tour = tour; _exporter = Global .ContainerDaySim.GetInstance <IPersistenceFactory <ITour> >() .Exporter; _tourCreator = Global .ContainerDaySim .GetInstance <IWrapperFactory <ITourCreator> >() .Creator; // relations properties Household = personWrapper.Household; Person = personWrapper; PersonDay = personDayWrapper; OriginParcel = originParcel; DestinationParcel = destinationParcel; DestinationPurpose = destinationPurpose; DestinationArrivalTime = destinationArrivalTime; DestinationDepartureTime = destinationDepartureTime; DestinationPurpose = destinationPurpose; // flags/choice model/etc. properties SetValueOfTimeCoefficients(destinationPurpose, true); }
public TourWrapper(ITour tour, IPersonDayWrapper personDayWrapper, int purpose, bool suppressRandomVOT) { _tour = tour; _exporter = Global .ContainerDaySim .GetInstance <IPersistenceFactory <ITour> >() .Exporter; _tourCreator = Global .ContainerDaySim .GetInstance <IWrapperFactory <ITourCreator> >() .Creator; // relations properties Household = personDayWrapper.Household; Person = personDayWrapper.Person; PersonDay = personDayWrapper; Subtours = new List <ITourWrapper>(); SetParcelRelationships(tour); // flags/choice model/etc. properties SetValueOfTimeCoefficients(purpose, suppressRandomVOT); IsHomeBasedTour = true; TimeWindow = new TimeWindow(); }
/// <summary> /// Initialise une nouvelle instance de la classe <see cref="Execution"/>. /// </summary> /// <param name="demarrage">Classe de demarrage.</param> /// <param name="tour">Classe du tour.</param> public Execution( IDemarrage demarrage, ITour tour ) { this.Demarrage = demarrage; this.Tour = tour; }
public void SaveCommit(ITour tour, out bool success) { using (IUnitOfWork uow = UnitOfWork.Begin()) { Save(tour, out success); if (success) uow.Commit(); } }
//make it delete any shows it is related to. or not if you want those always kept. public void Delete(ITour tour) { Checks.Argument.IsNotNull(tour, "tour"); using (IUnitOfWork u = UnitOfWork.Begin()) { _repo.Remove(tour); u.Commit(); } }
public Partie(ITalon talon, IPioche pioche, ITour tour) { this.talon = talon; this.pioche = pioche; this.tour = tour; this.CarteJouee += CarteJoueeParJoueur; this.JoueurAPioche += JoueurATireUneCarte; Joueurs = new List <Joueur>(); }
//make it delete any shows it is related to. or not if you want those always kept. public void Delete( ITour tour ) { Checks.Argument.IsNotNull(tour, "tour"); using (IUnitOfWork u = UnitOfWork.Begin()) { _repo.Remove(tour); u.Commit(); } }
public void SaveCommit(ITour tour, out bool success) { using (IUnitOfWork uow = UnitOfWork.Begin()) { Save(tour, out success); if (success) { uow.Commit(); } } }
/// <summary> /// Creates new instance of TspLib95Item class /// </summary> /// <param name="problem">TSP problem to be encapsulated</param> /// <param name="optimalTour">Optimal tour of the problem</param> /// <param name="optimalTourDistance">Optimal tour distance</param> public TspLib95Item(IProblem problem, ITour optimalTour, double optimalTourDistance) { if (problem == null) { throw new ArgumentNullException("problem"); } Problem = problem; OptimalTour = optimalTour; _optimalTourDistance = optimalTourDistance; }
public void ConstructTours() { var files = new List <string>(Directory.EnumerateFiles(RootDir, "*.tour", SearchOption.AllDirectories)); foreach (var fileName in files) { ITour tour = Tour.FromFile(fileName); Assert.IsNotNull(tour); Assert.AreEqual(tour.Dimension, tour.Nodes.Count); } }
/// <summary> /// Gets tour distance for a given problem /// </summary> /// <param name="tour">Tour to check</param> /// <returns>Tour distance</returns> public override double TourDistance(ITour tour) { ValidateTour(tour); double distance = 0; for (int i = -1; i + 1 < tour.Nodes.Count; i++) { INode first = i == -1 ? NodeProvider.GetNode(tour.Nodes.Last()) : NodeProvider.GetNode(tour.Nodes[i]); INode second = NodeProvider.GetNode(tour.Nodes[i + 1]); double weight = EdgeWeightsProvider.GetWeight(first, second); distance += weight; } return(distance); }
public TourViewModel(ITour tour) { TourId = tour.TourId; Name = tour.Name; UrlName = tour.UrlName; City = tour.City; Category = TourTypesConverter.ConvertToString(tour.Category); Price = tour.Price; Stars = tour.Stars; Description = tour.Description; Country = tour.Country; Nights = tour.Nights; IsFlightIncluded = tour.IsFlightIncluded; NewImageCollection = new List <string>(); OldImageCollection = tour.ImageIdCollection.ToList(); }
private void SetParcelRelationships(ITour tour) { IParcelWrapper originParcel; if (tour.OriginParcelId != Constants.DEFAULT_VALUE && ChoiceModelFactory.Parcels.TryGetValue(tour.OriginParcelId, out originParcel)) { OriginParcel = originParcel; } IParcelWrapper destinationParcel; if (tour.DestinationParcelId != Constants.DEFAULT_VALUE && ChoiceModelFactory.Parcels.TryGetValue(tour.DestinationParcelId, out destinationParcel)) { DestinationParcel = destinationParcel; } }
private static void AssertHCPTourDistance(string problemFileName, string tourFileName) { var problemTspFile = Path.Combine(RootDir, problemFileName); var tourTspFile = TspFile.Load(Path.Combine(RootDir, tourFileName)); Assert.IsNotNull(problemTspFile); Assert.IsNotNull(tourTspFile); var problem = HamiltonianCycleProblem.FromFile(problemTspFile); Assert.IsNotNull(problem); ITour tour = Tour.FromTspFile(tourTspFile); Assert.IsNotNull(tour); Assert.AreEqual(problem.OptimalTourDistance, problem.TourDistance(tour)); }
//consider changing the out parameter to a validation type object public void Save(ITour tour, out bool success) { Checks.Argument.IsNotNull(tour, "tour"); success = false; if (null == _repo.FindByTourId(tour.TourId)) { try { _repo.Add(tour); success = true; } catch (Exception ex) { success = false; } } }
/// <summary> /// Generic problem loading routine /// </summary> /// <param name="name">problem name</param> /// <param name="type">problem class type</param> /// <param name="extension">problem file extension</param> /// <param name="dir">directory with problems of such type</param> /// <param name="solutionsFile">name of file with opt distances</param> /// <param name="optTourExtension">extension for files with opt tours</param> /// <returns>A list of the TspLib95Items loaded</returns> /// <exception cref="ArgumentNullException">Thrown if "name" argument is null or empty.</exception> /// <exception cref="DirectoryNotFoundException">Thrown if TSP lib path (<seealso cref="TspLib95"/>) does not point to TSPLIB95.</exception> private void ProblemLoader(string name, string type, string extension, string dir, string solutionsFile, string optTourExtension) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } name = name.Replace(extension, ""); var instancesDir = Path.Combine(_tspLib95Path, dir); if (!Directory.Exists(instancesDir)) { throw new DirectoryNotFoundException(); } var instancePattern = name + extension; var solutions = LoadBestSolutionsFile(Path.Combine(instancesDir, solutionsFile)); foreach (var file in Directory.GetFiles(instancesDir, instancePattern)) { var problem = FactorizeProblem(file, type); ITour tour = null; var tourName = file.Replace(extension, optTourExtension); if (File.Exists(tourName)) { tour = Tour.FromFile(tourName); } var distance = double.MaxValue; if (solutions.ContainsKey(problem.Name)) { distance = solutions[problem.Name]; } Items.Add(new TspLib95Item(problem, tour, distance)); } }
/// <summary> /// Validate given solution /// </summary> /// <param name="tour">Tour to check</param> private void ValidateTour(ITour tour) { if (tour == null) { throw new ArgumentNullException("tour"); } if (tour.Dimension != tour.Nodes.Count) { throw new TourInvalidException("Tour dimension does not match number of nodes on a list"); } // Fast check for the sake of speed. var set = new HashSet <int>(tour.Nodes); set.UnionWith(NodeProvider.GetNodes().Select(n => n.Id)); if (set.Count == tour.Nodes.Count) { return; } // Slow check for a more detailed exception message. var identifiers = new HashSet <int>(); foreach (var nodeId in tour.Nodes) { if (identifiers.Contains(nodeId)) { throw new TourInvalidException("Tour is invalid, has a node " + nodeId + " multiple times"); } if (null == NodeProvider.GetNode(nodeId)) { throw new TourInvalidException("Tour is invalid, has a node " + nodeId + " which is not present in a problem"); } identifiers.Add(nodeId); } }
/// <summary> /// Gets tour distance for a given problem /// </summary> /// <param name="tour">Tour to check</param> /// <returns>Tour distance</returns> public override double TourDistance(ITour tour) { throw new NotImplementedException(); }
/// <summary> /// Gets tour distance for a given problem /// </summary> /// <param name="tour">Tour to check</param> /// <returns>Tour distance</returns> public abstract double TourDistance(ITour tour);
public TourWrapper(ITour tour, IPersonDayWrapper personDayWrapper, int purpose, bool suppressRandomVOT = false) : base(tour, personDayWrapper, purpose, suppressRandomVOT) { _tour = (ILDTour)tour; }
public TourWrapper(ITour tour, IPersonDayWrapper personDayWrapper, bool suppressRandomVOT = false) : base(tour, personDayWrapper, Global.Settings.Purposes.PersonalBusiness, suppressRandomVOT) { _tour = (ILDTour)tour; }
public TourWrapper(ITour subtour, ITourWrapper tourWrapper, int purpose, bool suppressRandomVOT = false) : base(subtour, tourWrapper, purpose, suppressRandomVOT) { _tour = (ILDTour)subtour; }
public TourWrapper(ITour subtour, ITourWrapper tourWrapper, bool suppressRandomVOT = false) : base(subtour, tourWrapper, Global.Settings.Purposes.PersonalBusiness, suppressRandomVOT) { _tour = (ILDTour)subtour; }
public TourWrapper(ITour tour, IPersonWrapper personWrapper, IPersonDayWrapper personDayWrapper, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int destinationPurpose) : base(tour, personWrapper, personDayWrapper, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose) { _tour = (ILDTour)tour; }
ITourWrapper ITourCreator.CreateWrapper(ITour tour, IPersonDayWrapper personDayWrapper, int purpose, bool suppressRandomVOT) { return(CreateWrapper(tour, personDayWrapper, purpose, suppressRandomVOT)); }
/// <summary> /// Gets tour distance for a given problem /// </summary> /// <param name="tour">Tour to check</param> /// <returns>Tour distance</returns> public override double TourDistance(ITour tour) { ValidateTour(tour); double distance = 0; for (int i = -1; i + 1 < tour.Nodes.Count; i++) { INode first = i == -1 ? NodeProvider.GetNode(tour.Nodes.Last()) : NodeProvider.GetNode(tour.Nodes[i]); INode second = NodeProvider.GetNode(tour.Nodes[i + 1]); double weight = EdgeWeightsProvider.GetWeight(first, second); distance += weight; } return distance; }
ITourWrapper ITourCreator.CreateWrapper(ITour subtour, ITourWrapper tourWrapper, int purpose, bool suppressRandomVOT) { return(CreateWrapper(subtour, tourWrapper, purpose, suppressRandomVOT)); }
/// <summary> /// Pretends to shift the given customer to a new location and places it after the given 'before' customer. /// </summary> /// <param name="customer">The customer to shift.</param> /// <param name="before">The new customer that will come right before.</param> /// <returns>The enumerable that represents the new route.</returns> /// <remarks>example: /// route: 1->2->3->4->5->6 /// customer: 2 /// before: 4 /// /// new route: 1->3->4->2->5->6 /// </remarks> /// <exception cref="System.ArgumentException">When customer equals before.</exception> public static ShiftedAfterTour GetShiftedAfter(this ITour tour, int customer, int before) { return(new ShiftedAfterTour(tour, customer, before)); }
/// <summary> /// Validate given solution /// </summary> /// <param name="tour">Tour to check</param> private void ValidateTour(ITour tour) { throw new NotImplementedException(); }
/// <summary> /// Validate given solution /// </summary> /// <param name="tour">Tour to check</param> private void ValidateTour(ITour tour) { if (tour == null) { throw new ArgumentNullException("tour"); } if (tour.Dimension != tour.Nodes.Count) { throw new TourInvalidException("Tour dimension does not match number of nodes on a list"); } HashSet<int> identifiers = new HashSet<int>(); foreach (int nodeId in tour.Nodes) { if (identifiers.Contains(nodeId)) { throw new TourInvalidException("Tour is invalid, has a node " + nodeId + " multiple times"); } if (null == NodeProvider.GetNode(nodeId)) { throw new TourInvalidException("Tour is invalid, has a node " + nodeId + " which is not present in a problem"); } identifiers.Add(nodeId); } }