private bool FoundModeWithName(string name, IModeChoiceNode mode) { if (mode.ModeName == name) { return(true); } var cat = mode as IModeCategory; if (cat != null) { var children = cat.Children; if (children == null) { return(false); } var length = children.Count; for (int i = 0; i < length; i++) { if (FoundModeWithName(name, children[i])) { return(true); } } } return(false); }
private TreeData <float[][]> GetAutoModeData(TreeData <float[][]> tree, IModeChoiceNode mode) { if (mode.ModeName == AutoModeName) { return(tree); } var cat = mode as IModeCategory; if (cat == null) { return(null); } var treeChildren = tree.Children; var modeChildren = cat.Children; // make sure that it actually contains children first if (treeChildren == null | modeChildren == null) { return(null); } for (int i = 0; i < treeChildren.Length; i++) { var temp = GetAutoModeData(treeChildren[i], modeChildren[i]); if (temp != null) { return(temp); } } return(null); }
private void WriteModeSplit(TreeData <float[][]> split, IModeChoiceNode modeNode, string directoryName) { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } using (StreamWriter writer = new StreamWriter(Path.Combine(directoryName, modeNode.ModeName + ".csv"))) { var header = true; var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData(); for (int i = 0; i < zones.Length; i++) { var first = true; if (header) { header = false; for (int j = 0; j < zones.Length; j++) { if (first) { first = false; writer.Write("Zones O\\D,"); writer.Write(zones[j].ZoneNumber); } else { writer.Write(','); writer.Write(j); } } writer.WriteLine(); first = true; } for (int j = 0; j < zones.Length; j++) { var s = split.Result[i][j]; if (first) { first = false; writer.Write(i); writer.Write(','); writer.Write(s); } else { writer.Write(','); writer.Write(s); } } writer.WriteLine(); } } if (split.Children != null) { for (int i = 0; i < split.Children.Length; i++) { WriteModeSplit(split.Children[i], ((IModeCategory)modeNode).Children[i], directoryName); } } }
private bool GatherUtility(TreeData <float[]> treeData, IModeChoiceNode node, int o, int d, IZone[] zones) { var cat = node as IModeCategory; int index = o * zones.Length + d; if (!node.Feasible(zones[o], zones[d], SimulationTime)) { treeData.Result[index] = float.NaN; return(false); } if (cat == null) { treeData.Result[index] = node.CurrentlyFeasible > 0 ? (float)Math.Exp(node.CalculateV(zones[o], zones[d], SimulationTime)) : float.NaN; return(!float.IsNaN(treeData.Result[index])); } else if (cat.Correlation > 0) { bool hasAlternatives = false; float totalUtility = 0; var treeChildren = treeData.Children; var catChildren = cat.Children; for (int i = 0; i < treeData.Children.Length; i++) { if (GatherUtility(treeChildren[i], catChildren[i], o, d, zones)) { hasAlternatives = true; totalUtility += treeChildren[i].Result[index]; } } if (hasAlternatives) { if (totalUtility >= this.MinLogSumToE) { var localUtility = cat.CalculateCombinedV(zones[o], zones[d], SimulationTime); if (cat.Correlation == 1f) { if (localUtility == 0f) { treeData.Result[index] = (float)(totalUtility); } else { treeData.Result[index] = (float)(totalUtility * Math.Exp(localUtility)); } } else { treeData.Result[index] = (float)(Math.Pow(totalUtility, cat.Correlation) * Math.Exp(localUtility)); } return(true); } } } treeData.Result[index] = float.NaN; return(false); }
internal void Apply(IModeChoiceNode mode, int parameterIndex) { if (Field != null) { Field.SetValue(mode, Values[parameterIndex]); } else { Property.SetValue(mode, Values[parameterIndex], null); } }
private static void CreateMirroredTree <T>(TreeData <T> node, IModeChoiceNode mode) { if (mode is IModeCategory asCat && asCat.Children != null) { node.Children = new TreeData <T> [asCat.Children.Count]; for (int j = 0; j < node.Children.Length; j++) { node.Children[j] = new TreeData <T>(); CreateMirroredTree(node.Children[j], asCat.Children[j]); } } }
private void WriteHeader(StreamWriter writer, IModeChoiceNode mode) { writer.Write(mode.ModeName); if (mode is IModeCategory cat) { foreach (var child in cat.Children) { writer.Write(','); WriteHeader(writer, child); } } }
private bool StoreProperty(IModeChoiceNode selectedMode, string parameterName, out FieldInfo field, out PropertyInfo property) { // Search for a field or property that has an attribute with this name field = null; property = null; var modeType = selectedMode.GetType(); foreach (var f in modeType.GetProperties()) { // search the attributes var attributes = f.GetCustomAttributes(true); foreach (var at in attributes) { // if we find an attribute from XTMF ParameterAttribute parameter; if ((parameter = (at as ParameterAttribute)) != null) { // Check to see if this is our parameter if (parameter.Name == parameterName) { property = f; return(true); } } } } foreach (var f in modeType.GetFields()) { // search the attributes var attributes = f.GetCustomAttributes(true); foreach (var at in attributes) { // if we find an attribute from XTMF ParameterAttribute parameter; if ((parameter = (at as ParameterAttribute)) != null) { // Check to see if this is our parameter if (parameter.Name == parameterName) { field = f; return(true); } } } } if (!IgnoreBadParameters) { // If we get here then we did not find it! throw new XTMFRuntimeException(this, "We were unable to find a parameter with the name \"" + parameterName + "\" in the mode " + selectedMode.ModeName); } return(false); }
private bool LinkMode(string modeName, out IModeChoiceNode mode) { var modes = this.Root.Modes; var length = modes.Count; for (int i = 0; i < length; i++) { if (LinkMode(modeName, modes[i], out mode)) { return(true); } } mode = null; return(false); }
private int GetNumberOfModes(IModeChoiceNode node) { var cat = node as IModeCategory; var total = 1; if (cat != null) { var children = cat.Children; var length = children.Count; for (int i = 0; i < length; i++) { total += GetNumberOfModes(children[i]); } } return(total); }
private void WriteModeSplit(TreeData <float[][]> split, IModeChoiceNode modeNode, string directoryName) { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } Task writeTask = new Task(delegate() { using (StreamWriter writer = new StreamWriter(Path.Combine(directoryName, modeNode.ModeName + ".csv"))) { var header = true; var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData(); for (int i = 0; i < zones.Length; i++) { if (header) { header = false; writer.Write("Zones O\\D"); for (int j = 0; j < zones.Length; j++) { writer.Write(','); writer.Write(zones[j].ZoneNumber); } writer.WriteLine(); } var row = split.Result == null ? null : split.Result[i]; writer.Write(zones[i].ZoneNumber); for (int j = 0; j < zones.Length; j++) { writer.Write(','); writer.Write(row == null ? 0 : row[j]); } writer.WriteLine(); } } }); writeTask.Start(); if (split.Children != null) { for (int i = 0; i < split.Children.Length; i++) { WriteModeSplit(split.Children[i], ((IModeCategory)modeNode).Children[i], directoryName); } } writeTask.Wait(); }
protected virtual bool LinkModeParameter(ref string error) { IModeChoiceNode mode = this.Parent.Mode; this.AssignTo = this.Parent.Mode; if (mode == null) { error = "In '" + this.Parent.Name + "' it failed to present a mode for '" + this.Name + "'!"; return(false); } var modeType = mode.GetType(); var parameterType = typeof(ParameterAttribute); foreach (var field in modeType.GetFields()) { var attributes = field.GetCustomAttributes(parameterType, true); if (attributes != null) { for (int i = 0; i < attributes.Length; i++) { if ((attributes[i] as ParameterAttribute).Name == this.ModeParameterName) { this.Field = field; return(true); } } } } foreach (var field in modeType.GetProperties()) { var attributes = field.GetCustomAttributes(parameterType, true); if (attributes != null) { for (int i = 0; i < attributes.Length; i++) { if ((attributes[i] as ParameterAttribute).Name == this.ModeParameterName) { this.Property = field; return(true); } } } } error = "We were unable to find a parameter in the mode '" + mode.ModeName + "' called '" + this.ModeParameterName + "'!"; return(false); }
protected void WriteModeSplit(TreeData <float[]> split, IModeChoiceNode modeNode, string directoryName) { Task writeTask = new Task(delegate { if (split.Result != null) { using (StreamWriter writer = new StreamWriter(Path.Combine(directoryName, modeNode.ModeName + ".csv"))) { var header = true; var zones = Root.ZoneSystem.ZoneArray.GetFlatData(); var data = split.Result; for (int i = 0; i < zones.Length; i++) { if (header) { header = false; writer.Write("Zones O\\D"); for (int j = 0; j < zones.Length; j++) { writer.Write(','); writer.Write(zones[j].ZoneNumber); } writer.WriteLine(); } writer.Write(zones[i].ZoneNumber); for (int j = 0; j < zones.Length; j++) { writer.Write(','); writer.Write(data[i * zones.Length + j]); } writer.WriteLine(); } } } }); writeTask.Start(); if (split.Children != null) { for (int i = 0; i < split.Children.Length; i++) { WriteModeSplit(split.Children[i], ((IModeCategory)modeNode).Children[i], directoryName); } } writeTask.Wait(); }
private bool GatherAllUtility(IModeChoiceNode node, IZone o, IZone d, out float utility) { var cat = node as IModeCategory; if (cat == null) { if (node.Feasible(o, d, SimulationTime)) { utility = (float)Math.Exp(node.CalculateV(o, d, SimulationTime)); return(!float.IsNaN(utility)); } } else { // check to make sure that we are feasible if (!node.Feasible(o, d, SimulationTime)) { utility = 0f; return(false); } // if we are feasible then go through and get the utility of our children float totalUtility = 0f; var length = cat.Children.Count; bool anyChildrenFeasible = false; for (int i = 0; i < length; i++) { float res; if (GatherAllUtility(cat.Children[i], o, d, out res)) { anyChildrenFeasible = true; totalUtility += res; } } if (anyChildrenFeasible) { utility = (float)(Math.Pow(totalUtility, cat.Correlation) * Math.Exp(cat.CalculateCombinedV(o, d, SimulationTime))); return(true); } } // if we got here then there were no feasible alternatives utility = 0f; return(false); }
protected void WriteModeSplit(TreeData <float[][]> split, IModeChoiceNode modeNode, string directoryName) { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } if (split.Result != null) { var zones = Root.ZoneSystem.ZoneArray.GetFlatData(); Functions.SaveData.SaveMatrix(zones, split.Result, Path.Combine(directoryName, modeNode.ModeName + ".csv")); } if (split.Children != null) { for (int i = 0; i < split.Children.Length; i++) { WriteModeSplit(split.Children[i], ((IModeCategory)modeNode).Children[i], directoryName); } } }
private bool FindOurMode(IModeChoiceNode node) { if (node.ModeName == ModeName) { _Mode = node; return(true); } if (node is IModeCategory cat) { for (int i = 0; i < cat.Children.Count; i++) { if (FindOurMode(cat)) { return(true); } } } return(false); }
private bool GetModeIndex(string trimmed, IModeChoiceNode node, ref int index) { if (node.ModeName == trimmed) { return(true); } index++; if (node is IModeCategory cat) { var length = cat.Children.Count; for (int i = 0; i < length; i++) { if (GetModeIndex(trimmed, cat.Children[i], ref index)) { return(true); } } } return(false); }
private bool FindOurMode(IModeChoiceNode node) { if (node.ModeName == this.ModeName) { this._Mode = node; return(true); } var cat = node as IModeCategory; if (cat != null) { for (int i = 0; i < cat.Children.Count; i++) { if (FindOurMode(cat)) { return(true); } } } return(false); }
private IModeChoiceNode GetMode(ref int current, int index, IModeChoiceNode mode) { if (current == index) { return(mode); } current++; if (mode is IModeCategory cat) { var length = cat.Children.Count; for (int i = 0; i < length; i++) { var m = GetMode(ref current, index, cat.Children[i]); if (m != null) { return(m); } } } return(null); }
private bool AttachMode(string modeName, ref IMode mode, IModeChoiceNode current) { // ReSharper disable once SuspiciousTypeConversion.Global if (mode is IModeCategory cat) { foreach (var m in Root.Modes) { if (AttachMode(modeName, ref mode, m)) { return(true); } } } else { if (modeName == current.ModeName) { return(current is IMode); } } return(false); }
private bool LinkModeName(string p, IModeChoiceNode current) { if (current.ModeName == p) { return(true); } if (current is IModeCategory cat) { var modes = cat.Children; var length = modes.Count; for (int i = 0; i < length; i++) { if (LinkModeName(p, modes[i])) { // insert at the front AutoDrivePath.Insert(0, i); return(true); } } } return(false); }
private bool LinkMode(string modeName, IModeChoiceNode current, out IModeChoiceNode mode) { if (current.ModeName == modeName) { mode = current; return(true); } if (current is IModeCategory cat) { var modes = cat.Children; var length = modes.Count; for (int i = 0; i < length; i++) { if (LinkMode(modeName, modes[i], out mode)) { return(true); } } } mode = null; return(false); }
private bool AttachMode(string modeName, ref IMode mode, IModeChoiceNode current) { var cat = mode as IModeCategory; if (cat != null) { foreach (var m in this.Root.Modes) { if (AttachMode(modeName, ref mode, m)) { return(true); } } } else { if (modeName == current.ModeName) { mode = current as IMode; return(mode != null); } } return(false); }
private bool LinkMode(string modeName, out IModeChoiceNode mode) { var modes = this.Root.Modes; var length = modes.Count; for ( int i = 0; i < length; i++ ) { if ( LinkMode( modeName, modes[i], out mode ) ) { return true; } } mode = null; return false; }
internal void Apply(IModeChoiceNode mode, int parameterIndex) { if ( this.Field != null ) { this.Field.SetValue( mode, Values[parameterIndex] ); } else { this.Property.SetValue( mode, Values[parameterIndex], null ); } }
private bool GatherAllUtility(IModeChoiceNode node, IZone o, IZone d, out float utility) { var cat = node as IModeCategory; if ( cat == null ) { if ( node.Feasible( o, d, SimulationTime ) ) { utility = (float)Math.Exp( node.CalculateV( o, d, SimulationTime ) ); return !float.IsNaN( utility ); } } else { // check to make sure that we are feasible if ( !node.Feasible( o, d, SimulationTime ) ) { utility = 0f; return false; } // if we are feasible then go through and get the utility of our children float totalUtility = 0f; var length = cat.Children.Count; bool anyChildrenFeasible = false; for ( int i = 0; i < length; i++ ) { float res; if ( GatherAllUtility( cat.Children[i], o, d, out res ) ) { anyChildrenFeasible = true; totalUtility += res; } } if ( anyChildrenFeasible ) { utility = (float)( Math.Pow( totalUtility, cat.Correlation ) * Math.Exp( cat.CalculateCombinedV( o, d, SimulationTime ) ) ); return true; } } // if we got here then there were no feasible alternatives utility = 0f; return false; }
private bool LinkMode(string modeName, IModeChoiceNode current, out IModeChoiceNode mode) { if ( current.ModeName == modeName ) { mode = current; return true; } var cat = current as IModeCategory; if ( cat != null ) { var modes = cat.Children; var length = modes.Count; for ( int i = 0; i < length; i++ ) { if ( LinkMode( modeName, modes[i], out mode ) ) { return true; } } } mode = null; return false; }
private bool FindOurMode(IModeChoiceNode node) { if ( node.ModeName == this.ModeName ) { this._Mode = node; return true; } var cat = node as IModeCategory; if ( cat != null ) { for ( int i = 0; i < cat.Children.Count; i++ ) { if ( FindOurMode( cat ) ) { return true; } } } return false; }
private void ProcessMode(TreeData<float[][]> treeData, int i, int j, float flow, IModeChoiceNode node, int matrixNumber) { var cat = node as IModeCategory; if ( cat != null ) { // then go 1 level deeper for ( int m = cat.Children.Count - 1; m >= 0; m-- ) { ProcessMode( treeData.Children[m], i, j, flow, cat.Children[m], matrixNumber ); } // then sum var sum = 0f; for ( int m = cat.Children.Count - 1; m >= 0; m-- ) { var res = treeData.Children[m].Result; if ( res == null || res[i] == null ) continue; sum += res[i][j]; } SetData( treeData.Result, i, j, sum ); } else { for ( int dataIndex = 0; dataIndex < this.Data.Count; dataIndex++ ) { if ( this.Data[dataIndex].Mode == node ) { var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData(); var data = this.Data[dataIndex].Data; if ( data == null ) { throw new XTMFRuntimeException( "In '" + this.Name + "' we tried to access the data for mode split from mode '" + this.Data[dataIndex].ModeName + "' however it was not initialized!" ); } if ( treeData.Result == null ) { lock ( treeData ) { Thread.MemoryBarrier(); if ( treeData.Result == null ) { treeData.Result = new float[zones.Length][]; } } } SetData( treeData.Result, i, j, flow * data.GetDataFrom( zones[i].ZoneNumber, zones[j].ZoneNumber, matrixNumber ) ); } } } }
private TreeData<float[][]> GetAutoModeData(TreeData<float[][]> tree, IModeChoiceNode mode) { if ( mode.ModeName == this.AutoModeName ) { return tree; } else { var cat = mode as IModeCategory; if ( cat == null ) { return null; } var treeChildren = tree.Children; var modeChildren = cat.Children; // make sure that it actually contains children first if ( treeChildren == null | modeChildren == null ) { return null; } for ( int i = 0; i < treeChildren.Length; i++ ) { var temp = GetAutoModeData( treeChildren[i], modeChildren[i] ); if ( temp != null ) { return temp; } } } return null; }
private bool StoreProperty(IModeChoiceNode selectedMode, string parameterName, out FieldInfo field, out PropertyInfo property) { // Search for a field or property that has an attribute with this name field = null; property = null; var modeType = selectedMode.GetType(); foreach ( var f in modeType.GetProperties() ) { // search the attributes var attributes = f.GetCustomAttributes( true ); foreach ( var at in attributes ) { // if we find an attribute from XTMF ParameterAttribute parameter; if ( ( parameter = ( at as XTMF.ParameterAttribute ) ) != null ) { // Check to see if this is our parameter if ( parameter.Name == parameterName ) { property = f; return true; } } } } foreach ( var f in modeType.GetFields() ) { // search the attributes var attributes = f.GetCustomAttributes( true ); foreach ( var at in attributes ) { // if we find an attribute from XTMF ParameterAttribute parameter; if ( ( parameter = ( at as XTMF.ParameterAttribute ) ) != null ) { // Check to see if this is our parameter if ( parameter.Name == parameterName ) { field = f; return true; } } } } if ( !IgnoreBadParameters ) { // If we get here then we did not find it! throw new XTMFRuntimeException( "We were unable to find a parameter with the name \"" + parameterName + "\" in the mode " + selectedMode.ModeName ); } return false; }
private bool GatherUtility(TreeData<float> treeData, IModeChoiceNode node, int o, int d, IZone[] zones) { var cat = node as IModeCategory; treeData.Result = float.NaN; if ( !node.Feasible( zones[o], zones[d], SimulationTime ) ) { treeData.Result = float.NaN; return false; } if ( cat == null ) { treeData.Result = ( node.CurrentlyFeasible > 0 ? (float)Math.Exp( node.CalculateV( zones[o], zones[d], SimulationTime ) ) : float.NaN ); return !float.IsNaN( treeData.Result ); } else if ( cat.CurrentlyFeasible > 0 ) { bool hasAlternatives = false; float totalUtility = 0; var treeChildren = treeData.Children; var catChildren = cat.Children; for ( int i = 0; i < treeData.Children.Length; i++ ) { if ( GatherUtility( treeChildren[i], catChildren[i], o, d, zones ) ) { hasAlternatives = true; totalUtility += treeChildren[i].Result; } } if ( hasAlternatives ) { if ( totalUtility >= this.MinLogSumToE ) { var localUtility = cat.CalculateCombinedV( zones[o], zones[d], SimulationTime ); treeData.Result = (float)( Math.Pow( totalUtility, cat.Correlation ) * Math.Exp( localUtility ) ); return true; } } } treeData.Result = float.NaN; return false; }
private bool GetModeIndex(string trimmed, IModeChoiceNode node, ref int index) { if ( node.ModeName == trimmed ) { return true; } index++; var cat = node as IModeCategory; if ( cat != null ) { var length = cat.Children.Count; for ( int i = 0; i < length; i++ ) { if ( GetModeIndex( trimmed, cat.Children[i], ref index ) ) { return true; } } } return false; }
private void WriteModeSplit(TreeData<float[][]> split, IModeChoiceNode modeNode, string directoryName) { if ( !Directory.Exists( directoryName ) ) { Directory.CreateDirectory( directoryName ); } Task writeTask = new Task( delegate() { using ( StreamWriter writer = new StreamWriter( Path.Combine( directoryName, modeNode.ModeName + ".csv" ) ) ) { var header = true; var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData(); for ( int i = 0; i < zones.Length; i++ ) { if ( header ) { header = false; writer.Write( "Zones O\\D" ); for ( int j = 0; j < zones.Length; j++ ) { writer.Write( ',' ); writer.Write( zones[j].ZoneNumber ); } writer.WriteLine(); } var row = split.Result == null ? null : split.Result[i]; writer.Write( zones[i].ZoneNumber ); for ( int j = 0; j < zones.Length; j++ ) { writer.Write( ',' ); writer.Write( row == null ? 0 : row[j] ); } writer.WriteLine(); } } } ); writeTask.Start(); if ( split.Children != null ) { for ( int i = 0; i < split.Children.Length; i++ ) { WriteModeSplit( split.Children[i], ( (IModeCategory)modeNode ).Children[i], directoryName ); } } writeTask.Wait(); }
private bool LinkModeName(string p, IModeChoiceNode current) { if ( current.ModeName == p ) { return true; } var cat = current as IModeCategory; if ( cat != null ) { var modes = cat.Children; var length = modes.Count; for ( int i = 0; i < length; i++ ) { if ( LinkModeName( p, modes[i] ) ) { // insert at the front this.AutoDrivePath.Insert( 0, i ); return true; } } } return false; }
private bool FoundModeWithName(string name, IModeChoiceNode mode) { if ( mode.ModeName == name ) return true; var cat = mode as IModeCategory; if ( cat != null ) { var children = cat.Children; if ( children == null ) return false; var length = children.Count; for ( int i = 0; i < length; i++ ) { if ( FoundModeWithName( name, children[i] ) ) return true; } } return false; }
private IModeChoiceNode GetMode(ref int current, int index, IModeChoiceNode mode) { if ( current == index ) { return mode; } current++; var cat = mode as IModeCategory; if ( cat != null ) { var length = cat.Children.Count; for ( int i = 0; i < length; i++ ) { var m = GetMode( ref current, index, cat.Children[i] ); if ( m != null ) { return m; } } } return null; }
private void ProcessMode(TreeData <float[][]> treeData, int i, int j, float flow, IModeChoiceNode node, int matrixNumber) { if (node is IModeCategory cat) { // then go 1 level deeper for (int m = cat.Children.Count - 1; m >= 0; m--) { ProcessMode(treeData.Children[m], i, j, flow, cat.Children[m], matrixNumber); } // then sum var sum = 0f; for (int m = cat.Children.Count - 1; m >= 0; m--) { var res = treeData.Children[m].Result; if (res == null || res[i] == null) { continue; } sum += res[i][j]; } SetData(treeData.Result, i, j, sum); } else { for (int dataIndex = 0; dataIndex < Data.Count; dataIndex++) { if (Data[dataIndex].Mode == node) { var zones = Root.ZoneSystem.ZoneArray.GetFlatData(); var data = Data[dataIndex].Data; if (data == null) { throw new XTMFRuntimeException(this, "In '" + Name + "' we tried to access the data for mode split from mode '" + Data[dataIndex].ModeName + "' however it was not initialized!"); } if (treeData.Result == null) { lock (treeData) { Thread.MemoryBarrier(); if (treeData.Result == null) { treeData.Result = new float[zones.Length][]; } } } SetData(treeData.Result, i, j, flow * data.GetDataFrom(zones[i].ZoneNumber, zones[j].ZoneNumber, matrixNumber)); } } } }
private void WriteModeSplit(TreeData<float[][]> split, IModeChoiceNode modeNode, string directoryName) { if ( !Directory.Exists( directoryName ) ) { Directory.CreateDirectory( directoryName ); } using ( StreamWriter writer = new StreamWriter( Path.Combine( directoryName, modeNode.ModeName + ".csv" ) ) ) { var header = true; var zones = this.Root.ZoneSystem.ZoneArray.GetFlatData(); for(int i = 0; i < zones.Length; i++) { var first = true; if ( header ) { header = false; for(int j = 0; j < zones.Length; j++) { if ( first ) { first = false; writer.Write( "Zones O\\D," ); writer.Write( zones[j].ZoneNumber ); } else { writer.Write( ',' ); writer.Write( j ); } } writer.WriteLine(); first = true; } for ( int j = 0; j < zones.Length; j++ ) { var s = split.Result[i][j]; if ( first ) { first = false; writer.Write( i ); writer.Write( ',' ); writer.Write( s ); } else { writer.Write( ',' ); writer.Write( s ); } } writer.WriteLine(); } } if ( split.Children != null ) { for ( int i = 0; i < split.Children.Length; i++ ) { WriteModeSplit( split.Children[i], ( (IModeCategory)modeNode ).Children[i], directoryName ); } } }
private bool AttachMode(string modeName, ref IMode mode, IModeChoiceNode current) { var cat = mode as IModeCategory; if ( cat != null ) { foreach ( var m in this.Root.Modes ) { if ( AttachMode( modeName, ref mode, m ) ) { return true; } } } else { if ( modeName == current.ModeName ) { mode = current as IMode; return ( mode != null ); } } return false; }