public void TestSerialization() { Journey j = new Journey(); j.ShortName = "Jeff"; j.Description = "blah"; j.RunUuids = new[] { "a", "b", "c" }; var properties = j.Properties; var provider = new PtvDataProvider(); ObjectCache.RegisterObject(provider); properties.NetworkDataProviders = new[] { provider }; properties.PointDataProviders = new[] { new WalkingDataProvider() }; properties.PopulationSize = 100; properties.DepartureTime = DateTime.Now; properties.MutationRate = 0.1; properties.CrossoverRate = 0.7; // properties.Bidirectional = bidir; // properties.RouteGenerator = new AlRouteGenerator(properties); properties.SearchType = SearchType.Greedy_BiDir; properties.RouteGenerator = new DFSRoutePlanner(properties); properties.Mutator = new StandardMutator(properties); properties.Breeder = new StandardBreeder(properties); properties.FitnessFunction = new AlFitnessFunction(properties); properties.Database = new MySqlDatabase("20110606fordistributionforrmit"); properties.SearchType = SearchType.Greedy_BiDir; properties.Destination = new PtvNode(4, provider); properties.Origin = new PtvNode(4, provider); JourneyManager m = new JourneyManager(); m.Add(j); m.Save(); m = new JourneyManager(); var j2 = m.GetJourney(j.Uuid); Assert.That(j.Uuid == j2.Uuid); }
public ValidationError[] Search(string userKey, PropertyValue[] propVals) { var journeyManager = ObjectCache.GetObject<JourneyManager>(); if (journeyManager == null) { journeyManager = new JourneyManager(); ObjectCache.RegisterObject(journeyManager); } bool validationError = false; //Load the default journey Journey journey; try { if (journeyManager.Contains(userKey)) { journey = journeyManager.GetJourney(userKey); } else { journey = (Journey)journeyManager.GetJourney("default").Clone(); journey.Uuid = userKey; journeyManager.Add(journey); journeyManager.Save(); } } catch (KeyNotFoundException) { throw new Exception( "No default journey to base this journey off. Please specify one using the control panel."); } journeyManager.Clean(journey); journeyManager.Save(); /* FORMAT: { "propVals" : [{ "propVal" : {"name":"CrossoverRate","value":"0.7"} }] } */ if (propVals == null) { throw new Exception( "Property value collection is null. Cannot proceed with validation. Please check your JSON syntax."); } var valErrors = new List<ValidationError>(); foreach (var propVal in propVals) { var valError = this.SetProperty(journey, propVal); if (valError != null) { valErrors.Add(valError); if (valError.Message != Strings.VALIDATION_SUCCESS) { validationError = true; } } } // Only perform search if there are no validation errors. if (!validationError) { var optimiser = ObjectCache.GetObject<JourneyOptimiser>(); optimiser.Remove(journey); optimiser.EnqueueJourney(journey,1); optimiser.Resume(); } return valErrors.ToArray(); }
/// <summary> /// Initialises a new instance of the <see cref="JourneyOptimiser"/> class with the specified <see cref="JourneyManager"/> instance. /// </summary> /// <param name="journeyManager"> /// The journey manager associated with this system. /// </param> public JourneyOptimiser(JourneyManager journeyManager) { if (journeyManager == null) { throw new NullReferenceException(Strings.ERR_JM_NULL); } this.cTokenSource = new CancellationTokenSource(); this.journeyManager = journeyManager; this.bc = new BlockingCollection<string>(this.optimiseQueue); this.Load(); this.optimisationThread = new Thread(this.OptimisationLoop); this.optimisationThread.Start(); }