/// <inheritdoc/> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); if (!suppressDefaults || !IsDefaultRefractoryPeriods) { rootElem.Add(new XAttribute("refractoryPeriods", RefractoryPeriods.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultResistance) { rootElem.Add(Resistance.GetXml("resistance", suppressDefaults)); } if (!suppressDefaults || !IsDefaultDecayRate) { rootElem.Add(DecayRate.GetXml("decayRate", suppressDefaults)); } if (!suppressDefaults || !IsDefaultResetV) { rootElem.Add(ResetV.GetXml("resetV", suppressDefaults)); } if (!suppressDefaults || !IsDefaultFiringThresholdV) { rootElem.Add(FiringThresholdV.GetXml("firingThresholdV", suppressDefaults)); } Validate(rootElem, XsdTypeName); return(rootElem); }
//Methods /// <inheritdoc/> protected override void Check() { if (RefractoryPeriods < 0) { throw new ArgumentException($"Invalid RefractoryPeriods {RefractoryPeriods.ToString(CultureInfo.InvariantCulture)}. RefractoryPeriods must be GE to 0.", "RefractoryPeriods"); } return; }
/// <inheritdoc/> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); if (!suppressDefaults || !IsDefaultRefractoryPeriods) { rootElem.Add(new XAttribute("refractoryPeriods", RefractoryPeriods.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultSolverMethod) { rootElem.Add(new XAttribute("solverMethod", SolverMethod.ToString())); } if (!suppressDefaults || !IsDefaultSolverCompSteps) { rootElem.Add(new XAttribute("solverCompSteps", SolverCompSteps.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultStimuliDuration) { rootElem.Add(new XAttribute("stimuliDuration", StimuliDuration.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultTimeScale) { rootElem.Add(TimeScale.GetXml("timeScale", suppressDefaults)); } if (!suppressDefaults || !IsDefaultResistance) { rootElem.Add(Resistance.GetXml("resistance", suppressDefaults)); } if (!suppressDefaults || !IsDefaultRestV) { rootElem.Add(RestV.GetXml("restV", suppressDefaults)); } if (!suppressDefaults || !IsDefaultResetV) { rootElem.Add(ResetV.GetXml("resetV", suppressDefaults)); } if (!suppressDefaults || !IsDefaultRheobaseV) { rootElem.Add(RheobaseV.GetXml("rheobaseV", suppressDefaults)); } if (!suppressDefaults || !IsDefaultFiringThresholdV) { rootElem.Add(FiringThresholdV.GetXml("firingThresholdV", suppressDefaults)); } if (!suppressDefaults || !IsDefaultSharpnessDeltaT) { rootElem.Add(SharpnessDeltaT.GetXml("sharpnessDeltaT", suppressDefaults)); } Validate(rootElem, XsdTypeName); return(rootElem); }
/// <summary> /// Generates xml element containing the settings. /// </summary> /// <param name="rootElemName">Name to be used as a name of the root element.</param> /// <param name="suppressDefaults">Specifies whether to ommit optional nodes having set default values</param> /// <returns>XElement containing the settings</returns> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); if (!suppressDefaults || !IsDefaultRefractoryPeriods) { rootElem.Add(new XAttribute("refractoryPeriods", RefractoryPeriods.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultSolverMethod) { rootElem.Add(new XAttribute("solverMethod", SolverMethod.ToString())); } if (!suppressDefaults || !IsDefaultSolverCompSteps) { rootElem.Add(new XAttribute("solverCompSteps", SolverCompSteps.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultStimuliDuration) { rootElem.Add(new XAttribute("stimuliDuration", StimuliDuration.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultRecoveryTimeScale) { rootElem.Add(RecoveryTimeScale.GetXml("recoveryTimeScale", suppressDefaults)); } if (!suppressDefaults || !IsDefaultRecoverySensitivity) { rootElem.Add(RecoverySensitivity.GetXml("recoverySensitivity", suppressDefaults)); } if (!suppressDefaults || !IsDefaultRecoveryReset) { rootElem.Add(RecoveryReset.GetXml("recoveryReset", suppressDefaults)); } if (!suppressDefaults || !IsDefaultRestV) { rootElem.Add(RestV.GetXml("restV", suppressDefaults)); } if (!suppressDefaults || !IsDefaultResetV) { rootElem.Add(ResetV.GetXml("resetV", suppressDefaults)); } if (!suppressDefaults || !IsDefaultFiringThresholdV) { rootElem.Add(FiringThresholdV.GetXml("firingThresholdV", suppressDefaults)); } Validate(rootElem, XsdTypeName); return(rootElem); }
//Methods /// <summary> /// Checks consistency /// </summary> protected override void Check() { if (RefractoryPeriods < 0) { throw new ArgumentException($"Invalid RefractoryPeriods {RefractoryPeriods.ToString(CultureInfo.InvariantCulture)}. RefractoryPeriods must be GE to 0.", "RefractoryPeriods"); } if (SolverCompSteps < 1) { throw new ArgumentException($"Invalid SolverCompSteps {SolverCompSteps.ToString(CultureInfo.InvariantCulture)}. SolverCompSteps must be GE to 1.", "SolverCompSteps"); } if (StimuliDuration <= 0) { throw new ArgumentException($"Invalid StimuliDuration {StimuliDuration.ToString(CultureInfo.InvariantCulture)}. StimuliDuration must be GT 0.", "StimuliDuration"); } return; }
/// <summary> /// Removes vertex from the list of digraph vertices /// </summary> /// <param name="index">Index of the vertex in the list</param> /// <exception cref="ArgumentOutOfRangeException"/> public void RemoveVertex(int index) { if (Vertices.Count <= index || index < 0) { throw new ArgumentOutOfRangeException(nameof(index), @"Index of the vertex must be a non-negative number less than the number of elements in the vertices list"); } Arcs = Arcs.Where(arc => arc.StartVertex != index && arc.EndVertex != index).ToList(); Arcs = Arcs.ConvertAll(arc => new Arc(arc.StartVertex > index ? arc.StartVertex - 1 : arc.StartVertex, arc.EndVertex > index ? arc.EndVertex - 1 : arc.EndVertex)); var removed = Vertices[index]; Vertices.RemoveAt(index); Thresholds.RemoveAt(index); RefractoryPeriods.RemoveAt(index); State.RemoveAt(index); VertexRemoved?.Invoke(removed, new DigraphChangedEventArgs(index)); }
/// <summary> /// Adds vertex to the list of digraph vertices /// </summary> /// <param name="vertex">Vertex to add</param> /// <param name="threshold">Vertex threshold</param> /// <param name="refractoryPeriod">Vertex refractory period</param> /// <param name="initialState">Vertex initial state</param> /// <param name="index">Vertex index</param> /// <exception cref="ArgumentOutOfRangeException"/> public void AddVertex(Vertex vertex, int threshold = 1, int refractoryPeriod = 0, int initialState = 0, int index = -1) { if (Vertices.Count >= 200) { throw new InvalidOperationException(@"Too many vertices. Unable to add a new one."); } if (threshold <= 0) { throw new ArgumentOutOfRangeException(nameof(threshold), @"The value of the vertex threshold must be a positive number"); } if (refractoryPeriod < 0) { throw new ArgumentOutOfRangeException(nameof(refractoryPeriod), @"The value of the vertex refractory period must be a non-negative number"); } if (initialState < 0) { throw new ArgumentOutOfRangeException(nameof(initialState), @"The value of the vertex initial state must be a non-negative number"); } if (index == -1) { index = Vertices.Count; } Vertices.Insert(index, vertex); Thresholds.Insert(index, threshold); RefractoryPeriods.Insert(index, refractoryPeriod); State.Insert(index, initialState); Arcs = Arcs.ConvertAll(arc => new Arc(arc.StartVertex >= index ? arc.StartVertex + 1 : arc.StartVertex, arc.EndVertex >= index ? arc.EndVertex + 1 : arc.EndVertex, arc.Length)); VertexAdded?.Invoke(vertex, new DigraphChangedEventArgs(index)); }
/// <inheritdoc /> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName); if (!suppressDefaults || !IsDefaultRefractoryPeriods) { rootElem.Add(new XAttribute("refractoryPeriods", RefractoryPeriods.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultSolverMethod) { rootElem.Add(new XAttribute("solverMethod", SolverMethod.ToString())); } if (!suppressDefaults || !IsDefaultSolverCompSteps) { rootElem.Add(new XAttribute("solverCompSteps", SolverCompSteps.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultStimuliDuration) { rootElem.Add(new XAttribute("stimuliDuration", StimuliDuration.ToString(CultureInfo.InvariantCulture))); } Validate(rootElem, XsdTypeName); return(rootElem); }