/// <summary> /// Create a new Demand object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="fulfilled">Initial value of the Fulfilled property.</param> /// <param name="dateTime">Initial value of the DateTime property.</param> public static Demand CreateDemand(global::System.Int32 id, global::System.Boolean fulfilled, global::System.DateTime dateTime) { Demand demand = new Demand(); demand.Id = id; demand.Fulfilled = fulfilled; demand.DateTime = dateTime; return demand; }
/// <summary> /// Deprecated Method for adding a new object to the Demands EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToDemands(Demand demand) { base.AddObject("Demands", demand); }
private static void GenerateDemands(string cfgName, ProgressWindow progress) { try { Logger.LogInfo("Adding demand pool..."); using (var ctx = new CityContainer()) { var cfg = ctx.Configurations.Single(c => c.Name == cfgName); var peopleInConfiguration = ctx.People.Where(p => p.Address.District.Configuration.Name == cfgName).OrderBy(o => o.Id); //poi types from poi list (not configuration) because some poi types might be missing (not found) var poiTypeCollections = ctx.Pois.Select(p => p.Type); var poiSet = new HashSet<PoiType>(); foreach (var poiTypeCollection in poiTypeCollections) foreach (var poiType in poiTypeCollection) poiSet.Add(poiType); var statisticalData = new StatisticalData(); var totalDays = cfg.SimulationEndDate.Subtract(cfg.SimulationStartDate).Days + 1; var totalPeople = peopleInConfiguration.Count(); var demandsPerDay = (int) (totalPeople * cfg.PersonDemandsPerDay); var totalDemands = totalDays * demandsPerDay; for (var dayNr = 0; dayNr < totalDays; dayNr++) { var currentDate = cfg.SimulationStartDate.AddDays(dayNr); for (var demandNr = 0; demandNr < demandsPerDay; demandNr++) { if (progress.Worker.CancellationPending) { progress.Args.Cancel = true; _simulationCancelled = true; return; } var randomPersonIndex = Random.Next(0, totalPeople); var person = peopleInConfiguration.Skip(randomPersonIndex).First(); var demandDateTime = currentDate .AddHours(Random.Next(0, 24)) .AddMinutes(Random.Next(0, 60)) .AddSeconds(Random.Next(0, 60)); var demand = new Demand { Person = person, DateTime = demandDateTime, PoiType = statisticalData.TakePoiByDistribution(poiSet) }; ctx.Demands.AddObject(demand); ++progress.Current; progress.InvokeUpdate(totalDemands, GeneratingDemandsMsg); } } progress.InvokeUpdate(totalDemands, GeneratingDemandsMsg + PersistingMsg); ctx.SaveChanges(); // Persist after each day. } Logger.LogInfo("Demands pool added."); } catch(Exception e1) { Logger.LogInfo(e1.Message); } }