Skip to content

Commit

Permalink
Merge pull request #113 from RSGInc/distributed
Browse files Browse the repository at this point in the history
DaySimController (i.e. distributed DaySim) works again.  #61, #86
  • Loading branch information
bstabler committed Apr 11, 2017
2 parents 34cf1d9 + 12952c7 commit e3656fc
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 155 deletions.
2 changes: 2 additions & 0 deletions DaySim.Framework/Core/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public sealed class Configuration {
[XmlAttribute]
public string RemoteMachines { get; set; }

[XmlAttribute]
public bool RemoteCopySPFilesToRemoteMachines { get; set; }

[XmlAttribute]
public string NodeIndexPath { get; set; }
Expand Down
91 changes: 91 additions & 0 deletions DaySim.Framework/Core/ConfigurationManagerRSG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,96 @@ private static Configuration Deserialize(Stream stream) {

return configuration;
}

public Configuration OverrideConfiguration(Configuration configuration, string overrides)
{
//read possible overrides
string[] nameValuePairs = overrides.Trim().Split(',');
// if (nameValuePairs.Length)
if (nameValuePairs.Length > 0 && nameValuePairs[0].Trim().Length > 0)
{
Dictionary<string, string> keyValuePairs = nameValuePairs
.Select(value => value.Split('='))
.ToDictionary(pair => pair[0].Trim(), pair => pair[1].Trim());

var type1 = configuration.GetType();
foreach (KeyValuePair<string, string> entry in keyValuePairs)
{
var property = type1.GetProperty(entry.Key, BindingFlags.Public | BindingFlags.Instance);

if (property == null)
{
Console.WriteLine("WARNING: override key value pair ignored because key not found!: " + entry);
continue;
}

var type2 = property.PropertyType;

try
{
if (type2 == typeof(char))
{
var b = Convert.ChangeType(entry.Value, typeof(byte));

property.SetValue(configuration, Convert.ChangeType(b, type2), null);
}
else
{
property.SetValue(configuration, Convert.ChangeType(entry.Value, type2), null);
}
Console.WriteLine("Configuration override applied: " + entry);
}
catch
{
var builder = new StringBuilder();

builder
.AppendFormat("Error overriding configuration file for entry {0}.", entry).AppendLine()
.AppendFormat("Cannot convert the value of \"{0}\" to the type of {1}.", entry.Value, type2.Name).AppendLine()
.AppendLine("Please ensure that the value is in the correct format for the given type.");

throw new Exception(builder.ToString());
}
}
}
return (configuration);
}

public Configuration ProcessPath(Configuration configuration, string configurationPath)
{

if (string.IsNullOrWhiteSpace(configuration.BasePath))
{
//issue #52 use configuration file folder as default basepath rather than arbitrary current working directory.
configuration.BasePath = Path.GetDirectoryName(Path.GetFullPath(configurationPath));
}

//copy the configuration file into the output so we can tell if configuration changed before regression test called.
var archiveConfigurationFilePath = Global.GetOutputPath("archive_" + Path.GetFileName(configurationPath));
archiveConfigurationFilePath.CreateDirectory(); //create output directory if needed
File.Copy(configurationPath, archiveConfigurationFilePath, /* overwrite */ true);

return (configuration);
}

public PrintFile ProcessPrintPath(PrintFile printFile, string printFilePath)
{

if (string.IsNullOrWhiteSpace(printFilePath))
{
printFilePath = Global.GetOutputPath(PrintFile.DEFAULT_PRINT_FILENAME);
}

if (string.IsNullOrWhiteSpace(printFilePath))
{
printFilePath = Global.GetOutputPath(PrintFile.DEFAULT_PRINT_FILENAME);
}

printFilePath.CreateDirectory(); //create printfile directory if needed
printFile = new PrintFile(printFilePath, Global.Configuration);
Write(Global.Configuration, printFile);

return (printFile);
}
}
}
83 changes: 80 additions & 3 deletions DaySim/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DaySim.AggregateLogsums;
using DaySim.ChoiceModels;
using DaySim.DomainModels.Default;
using DaySim.DomainModels.Factories;
using DaySim.Framework.ChoiceModels;
using DaySim.Framework.Core;
using DaySim.Framework.DomainModels.Creators;
Expand All @@ -18,14 +19,17 @@
using DaySim.Framework.Roster;
using DaySim.ParkAndRideShadowPricing;
using DaySim.Sampling;
using DaySim.Settings;
using DaySim.ShadowPricing;
using HDF5DotNet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading;
using Timer = DaySim.Framework.Core.Timer;

Expand Down Expand Up @@ -330,9 +334,15 @@ private static void InitializeOutput() {
Global.Configuration.OutputHouseholdPath = Global.GetOutputPath(Global.Configuration.OutputHouseholdPath).ToIndexedPath(_index);
Global.Configuration.OutputPersonPath = Global.GetOutputPath(Global.Configuration.OutputPersonPath).ToIndexedPath(_index);
Global.Configuration.OutputHouseholdDayPath = Global.GetOutputPath(Global.Configuration.OutputHouseholdDayPath).ToIndexedPath(_index);
Global.Configuration.OutputJointTourPath = Global.GetOutputPath(Global.Configuration.OutputJointTourPath).ToIndexedPath(_index);
Global.Configuration.OutputFullHalfTourPath = Global.GetOutputPath(Global.Configuration.OutputFullHalfTourPath).ToIndexedPath(_index);
Global.Configuration.OutputPartialHalfTourPath = Global.GetOutputPath(Global.Configuration.OutputPartialHalfTourPath).ToIndexedPath(_index);
if (!string.IsNullOrEmpty(Global.Configuration.OutputJointTourPath)) {
Global.Configuration.OutputJointTourPath = Global.GetOutputPath(Global.Configuration.OutputJointTourPath).ToIndexedPath(_index);
}
if (!string.IsNullOrEmpty(Global.Configuration.OutputFullHalfTourPath)) {
Global.Configuration.OutputFullHalfTourPath = Global.GetOutputPath(Global.Configuration.OutputFullHalfTourPath).ToIndexedPath(_index);
}
if (!string.IsNullOrEmpty(Global.Configuration.OutputPartialHalfTourPath)) {
Global.Configuration.OutputPartialHalfTourPath = Global.GetOutputPath(Global.Configuration.OutputPartialHalfTourPath).ToIndexedPath(_index);
}
Global.Configuration.OutputPersonDayPath = Global.GetOutputPath(Global.Configuration.OutputPersonDayPath).ToIndexedPath(_index);
Global.Configuration.OutputTourPath = Global.GetOutputPath(Global.Configuration.OutputTourPath).ToIndexedPath(_index);
Global.Configuration.OutputTripPath = Global.GetOutputPath(Global.Configuration.OutputTripPath).ToIndexedPath(_index);
Expand Down Expand Up @@ -1503,5 +1513,72 @@ private static void OverrideImport(Configuration configuration, Expression<Func<
Global.PrintFile.WriteLine("{0} in the configuration file has been overridden, an import is required.", property.Name);
}
}

public static void InitializeDaySim()
{
var settingsFactory = new SettingsFactory(Global.Configuration);
Global.Settings = settingsFactory.Create();

ParallelUtility.Init(Global.Configuration);

//creating the DaySimModule does the non-model specific the SimpleInjector dependency injection registration
new DaySimModule();
//use the ModuleFactory to load the DaysimModule and the ModelModule (which could be Actum)
// which does the SimpleInjector dependency injection registration
var moduleFactory = new ModuleFactory(Global.Configuration);
moduleFactory.Load();

//after all dependency injection established, verify
Global.ContainerDaySim.Verify();

if (!string.IsNullOrEmpty(Global.Configuration.CustomizationDll))
{
if (Global.Configuration.DVRPC || Global.Configuration.JAX || Global.Configuration.Nashville || Global.Configuration.PSRC || Global.Configuration.SFCTA)
{
throw new Exception("Region specific flag is set such as DVRPC, JAX, Nashville, PSRC or SFCTA but CustomizationDll is already set to: " + Global.Configuration.CustomizationDll);
}
}
else if (Global.Configuration.DVRPC)
{
Global.Configuration.CustomizationDll = "DVRPC.dll";
if (Global.Configuration.JAX || Global.Configuration.Nashville || Global.Configuration.PSRC || Global.Configuration.SFCTA)
{
throw new Exception("More than one region specific flag such as DVRPC, JAX, Nashville, PSRC, or SFCTA was specified in configuration file.");
}
}
else if (Global.Configuration.JAX)
{
Global.Configuration.CustomizationDll = "JAX.dll";
if (Global.Configuration.DVRPC || Global.Configuration.Nashville || Global.Configuration.PSRC || Global.Configuration.SFCTA)
{
throw new Exception("More than one region specific flag such as DVRPC, JAX, Nashville, PSRC, or SFCTA was specified in configuration file.");
}
}
else if (Global.Configuration.Nashville)
{
Global.Configuration.CustomizationDll = "Nashville.dll";
if (Global.Configuration.DVRPC || Global.Configuration.JAX || Global.Configuration.PSRC || Global.Configuration.SFCTA)
{
throw new Exception("More than one region specific flag such as DVRPC, JAX, Nashville, PSRC, or SFCTA was specified in configuration file.");
}
}
else if (Global.Configuration.PSRC)
{
Global.Configuration.CustomizationDll = "PSRC.dll";
if (Global.Configuration.DVRPC || Global.Configuration.JAX || Global.Configuration.Nashville || Global.Configuration.SFCTA)
{
throw new Exception("More than one region specific flag such as DVRPC, JAX, Nashville, PSRC, or SFCTA was specified in configuration file.");
}
}
else if (Global.Configuration.SFCTA)
{
Global.Configuration.CustomizationDll = "SFCTA.dll";
if (Global.Configuration.DVRPC || Global.Configuration.JAX || Global.Configuration.Nashville || Global.Configuration.PSRC)
{
throw new Exception("More than one region specific flag such as DVRPC, JAX, Nashville, PSRC, or SFCTA was specified in configuration file.");
}
}
}

}
}
Loading

0 comments on commit e3656fc

Please sign in to comment.