protected void SetPresentValue(IValueStructure value) { //bool different = !(value == null && _presentStructure == null) // && !(_presentStructure != null && value != null && _presentStructure.Equals(value)); _presentStructure = value; //_properties.ValidatePropertiesAfterEvent(this); }
public IValueStructure[] Evaluate(params IValueStructure[] inputs) { if (inputs == null) { throw new ArgumentNullException("inputs"); } if (inputs.Length != _inputs.Count) { throw new System.ArgumentException("The count of inputs doesn't match the systems count of input signals.", "inputs"); } for (int i = 0; i < inputs.Length; i++) { _inputs[i].PostNewValue(inputs[i]); } Service <ISimulationMediator> .Instance.SimulateInstant(); IValueStructure[] outputs = new IValueStructure[_outputs.Count]; for (int i = 0; i < outputs.Length; i++) { outputs[i] = _outputs[i].Value; } return(outputs); }
public static IValueStructure PolynomialDegree(Signal signal, Signal[] generalizedVariables) { if (signal == null) { throw new ArgumentNullException("signal"); } if (signal.IsDrivenByPortEntity("Add", "Std")) { IntegerValue d = IntegerValue.Zero; ISignalSet inputs = signal.DrivenByPort.InputSignals; for (int i = 0; i < inputs.Count; i++) { IValueStructure f = MonomialDegree(inputs[i], generalizedVariables); if (f is UndefinedSymbol) { return(f); } else if (!(f is NegativeInfinitySymbol)) { d = d.Max((IntegerValue)f); } } return(d); } else { return(MonomialDegree(signal, generalizedVariables)); } }
private static IAccumulator Escalate(MathIdentifier structure, IValueStructure value, bool requireField) { if (structure.Equals(IntegerValue.TypeIdentifier)) { if (requireField) { return(Escalate <RationalValue, RationalValue>(value)); } else { return(Escalate <IntegerValue, RationalValue>(value)); } } if (structure.Equals(RationalValue.TypeIdentifier)) { return(Escalate <RationalValue, RationalValue>(value)); } if (structure.Equals(RealValue.TypeIdentifier)) { return(Escalate <RealValue, RealValue>(value)); } if (structure.Equals(ComplexValue.TypeIdentifier)) { return(Escalate <ComplexValue, ComplexValue>(value)); } throw new NotSupportedException(); }
public override bool Equals(IValueStructure other) { IntegerValue integerValue = other as IntegerValue; if (integerValue != null) { return(Equals(integerValue)); } RationalValue rationalValue = other as RationalValue; if (rationalValue != null) { return(rationalValue.Equals(this)); } RealValue realValue = other as RealValue; if (realValue != null) { return(realValue.Equals(this)); } return(other == this); }
protected void PublishToOutputs(IValueStructure value, TimeSpan delay) { for (int i = 0; i < outputs.Length; i++) { outputs[i].PostNewValue(value, delay); } }
public void UseCase_SystemAsCompoundArchitecture() { _p.KeepTrack = false; MathSystem s = _p.CurrentSystem; s.RemoveUnusedObjects(); Signal x = Binder.CreateSignal(); Std.ConstrainAlwaysReal(x); Signal x2 = StdBuilder.Square(x); Signal sinx2 = StdBuilder.Sine(x2); s.AddSignalTree(sinx2, true, true); s.RemoveUnusedObjects(); s.PublishToLibrary("SineOfSquaredX", "sinx2"); Signal y = Binder.CreateSignal(); y.PostNewValue(RealValue.E); Signal z = Service <IBuilder> .Instance.Function("sinx2", y); _p.SimulateInstant(); //.SimulateFor(new TimeSpan(1)); IValueStructure res = z.Value; RealValue resReal = RealValue.ConvertFrom(res); Assert.AreEqual(0.8939, Math.Round(resReal.Value, 4)); }
internal Signal(IValueStructure value) : base(value) { _properties = new PropertyBag(); _constraints = new PropertyBag(); Service<IMediator>.Instance.NotifyNewSignalCreated(this); }
public override bool Equals(IValueStructure other) { ToggleValue toggleValue = other as ToggleValue; if(toggleValue != null) return Equals(toggleValue); return other == this; }
internal Signal(IValueStructure value) : base(value) { _properties = new PropertyBag(); _constraints = new PropertyBag(); Service <IMediator> .Instance.NotifyNewSignalCreated(this); }
public static Signal DefineConstant(IValueStructure value) { Signal s = Binder.CreateSignal(value); s.Label = s.Value.ToString() + "_Constant"; s.EnableFlag(StdAspect.ConstantFlag); return(s); }
public override bool Equals(object obj) { IValueStructure vs = obj as IValueStructure; if (vs != null) { return(Equals(vs)); } return(false); }
public override bool Equals(IValueStructure other) { ToggleValue toggleValue = other as ToggleValue; if (toggleValue != null) { return(Equals(toggleValue)); } return(other == this); }
public override bool Equals(IValueStructure other) { LiteralValue literalValue = other as LiteralValue; if (literalValue != null) { return(Equals(literalValue)); } return(other == this); }
public override bool Equals(IValueStructure other) { VectorValue <TScalar> vectorValue = other as VectorValue <TScalar>; if (vectorValue != null) { return(Equals(vectorValue)); } return(other == this); }
public override bool Equals(IValueStructure other) { TokenValue integerValue = other as TokenValue; if (integerValue != null) { return(Equals(integerValue)); } return(false); }
public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) { if(delay < TimeSpan.Zero) return; if(delay == TimeSpan.Zero) ScheduleDeltaEvent(subject, value); else { _schedule.ScheduleDelayedEvent(subject, value, delay); _timeline.InsertTime(delay); } }
public Signal AddNamedSignal(string name, IValueStructure value) { if (_namedSignals == null) { _namedSignals = new Dictionary <string, Signal>(); } Signal signal = Binder.CreateSignal(value); AddSignal(signal); signal.Label = name; _namedSignals.Add(name, signal); return(signal); }
public IAccumulator Subtract(IValueStructure operand) { object other; if (ValueConverter <T> .TryConvertLosslessFrom(operand, out other)) { _value = _value.Subtract((T)other); return(this); } else { IAccumulator acc = Escalate(operand.TypeId, _value, false); return(acc.Subtract(operand)); } }
private static IAccumulator Escalate <TStructure, TStructureDivision>(IValueStructure value) where TStructure : IAlgebraicIntegralDomain <TStructure, TStructureDivision>, IValueStructure where TStructureDivision : IAlgebraicIntegralDomain <TStructureDivision, TStructureDivision>, IValueStructure { object val; if (ValueConverter <TStructure> .TryConvertLosslessFrom(value, out val)) { return(new Accumulator <TStructure, TStructureDivision>((TStructure)val)); } else { throw new NotSupportedException(); } }
public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) { LinkedList <SchedulerEventItem> timeline; if (!_delayedEvents.TryGetValue(subject.InstanceId, out timeline)) { timeline = new LinkedList <SchedulerEventItem>(); _delayedEvents.Add(subject.InstanceId, timeline); } if (timeline.Count == 0) { timeline.AddFirst(new SchedulerEventItem(subject, value, delay)); return; } TimeSpan d = TimeSpan.Zero; LinkedListNode <SchedulerEventItem> node = timeline.First; while (true) { if (d + node.Value.TimeSpan == delay) //already there... { TimeSpan relativeDelay = node.Value.TimeSpan; RemoveAllAfterIncluding(timeline, node); timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); return; } if (d + node.Value.TimeSpan > delay) //later events available { TimeSpan relativeDelay = delay - d; RemoveAllAfterIncluding(timeline, node); timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); return; } if (node.Next == null) //last { TimeSpan relativeDelay = delay - d - node.Value.TimeSpan; timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); return; } d += node.Value.TimeSpan; node = node.Next; } }
public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) { if (delay < TimeSpan.Zero) { return; } if (delay == TimeSpan.Zero) { ScheduleDeltaEvent(subject, value); } else { _schedule.ScheduleDelayedEvent(subject, value, delay); _timeline.InsertTime(delay); } }
public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) { LinkedList<SchedulerEventItem> timeline; if(!_delayedEvents.TryGetValue(subject.InstanceId, out timeline)) { timeline = new LinkedList<SchedulerEventItem>(); _delayedEvents.Add(subject.InstanceId, timeline); } if(timeline.Count == 0) { timeline.AddFirst(new SchedulerEventItem(subject, value, delay)); return; } TimeSpan d = TimeSpan.Zero; LinkedListNode<SchedulerEventItem> node = timeline.First; while(true) { if(d + node.Value.TimeSpan == delay) //already there... { TimeSpan relativeDelay = node.Value.TimeSpan; RemoveAllAfterIncluding(timeline, node); timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); return; } if(d + node.Value.TimeSpan > delay) //later events available { TimeSpan relativeDelay = delay - d; RemoveAllAfterIncluding(timeline, node); timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); return; } if(node.Next == null) //last { TimeSpan relativeDelay = delay - d - node.Value.TimeSpan; timeline.AddLast(new SchedulerEventItem(subject, value, relativeDelay)); return; } d += node.Value.TimeSpan; node = node.Next; } }
public IAccumulator IntegerPower(IValueStructure operand) { object other; if (ValueConverter <IntegerValue> .TryConvertLosslessFrom(operand, out other)) { return(IntegerPower((int)((IntegerValue)other).Value)); } if (ValueConverter <RationalValue> .TryConvertLosslessFrom(operand, out other)) { RationalValue rv = (RationalValue)other; if (rv.IsInteger) { return(IntegerPower((int)rv.NumeratorValue)); } } throw new NotSupportedException(); }
public void UseCase_ComplexDerivedSystemAsFunction() { // TODO: Replace with new (easier to use) MathFunction class instead of MathSystem _p.KeepTrack = false; MathSystem s = _p.CurrentSystem; Signal x = Binder.CreateSignal(); x.Label = "x"; Signal x2 = StdBuilder.Square(x); x2.Label = "x2"; Signal secx2 = StdBuilder.Secant(x2); secx2.Label = "secx2"; Signal diff = Std.Derive(secx2, x); diff.Label = "diff1"; s.AddSignalTree(diff, true, true); s.RemoveUnusedObjects(); Assert.AreEqual("2*sec(sqr(x))*tan(sqr(x))*x", _f.Format(diff, FormattingOptions.Compact), "Formatted Diff A"); Assert.AreEqual(1, s.InputCount, "Input Signal Count A"); Assert.AreEqual(1, s.OutputCount, "Output Signal Count A"); Assert.AreEqual(0, s.BusCount, "Bus Count A"); Assert.AreEqual(6, s.SignalCount, "Signal Count A"); Assert.AreEqual(4, s.PortCount, "Port Count A"); Signal diff2 = Std.AutoSimplify(diff); s.UnpromoteAsOutput(diff); s.AddSignalTree(diff2, true, true); s.RemoveUnusedObjects(); Assert.AreEqual("2*sec(sqr(x))*tan(sqr(x))*x", _f.Format(diff2, FormattingOptions.Compact), "Formatted Diff B"); Assert.AreEqual(1, s.InputCount, "Input Signal Count B"); Assert.AreEqual(1, s.OutputCount, "Output Signal Count B"); Assert.AreEqual(0, s.BusCount, "Bus Count B"); Assert.AreEqual(6, s.SignalCount, "Signal Count B"); Assert.AreEqual(4, s.PortCount, "Port Count B"); IValueStructure vs = s.Evaluate(ComplexValue.I)[0]; Assert.IsInstanceOfType(typeof(ComplexValue), vs, "Result is complex."); ComplexValue cv = (ComplexValue)vs; Assert.AreEqual(0, Math.Round(cv.RealValue, 4), "Real Result"); Assert.AreEqual(-5.7649, Math.Round(cv.ImaginaryValue, 4), "Imag Result"); }
/// <summary> /// Returns the coefficient factor in the monomial <see cref="signal"/> /// </summary> /// <returns> /// Constant UndefinedSymbol if <see cref="signal"/> is not a single-variable monomial. /// Otherwise the coefficient factor of the term. /// </returns> /// </returns> /// <remarks><see cref="signal"/> is assumed to be automatic simplified.</remarks> public static Signal MonomialCoefficient(Signal signal, Signal variable, out IValueStructure degree) { if (signal == null) { throw new ArgumentNullException("signal"); } if (Std.IsConstantAdditiveIdentity(signal)) { degree = NegativeInfinitySymbol.Instance; return(signal); } if (Std.IsAlwaysRational(signal)) { degree = IntegerValue.Zero; return(signal); } Signal coeff = IntegerValue.ConstantOne; if (signal.IsDrivenByPortEntity("Multiply", "Std") && signal.DrivenByPort.InputSignalCount == 2 && Std.IsAlwaysRational(signal.DrivenByPort.InputSignals[0])) { coeff = signal.DrivenByPort.InputSignals[0]; signal = signal.DrivenByPort.InputSignals[1]; } if (signal.Equals(variable)) { degree = IntegerValue.One; return(coeff); } if (signal.IsDrivenByPortEntity("Power", "Std")) { Signal b = signal.DrivenByPort.InputSignals[0]; Signal e = signal.DrivenByPort.InputSignals[1]; if (b.Equals(variable) && Std.IsAlwaysPositiveInteger(e)) { degree = e.Value; return(coeff); } } degree = UndefinedSymbol.Instance; return(UndefinedSymbol.Constant); }
public IAccumulator Divide(IValueStructure operand) { object other; if (ValueConverter <T> .TryConvertLosslessFrom(operand, out other)) { TDivision res = _value.Divide((T)other); if (_value is IAlgebraicDivisionExtension <T, T> ) { _value = (T)(object)res; return(this); } return(Escalate <TDivision, TDivision>(res)); } else { IAccumulator acc = Escalate(operand.TypeId, _value, true); return(acc.Divide(operand)); } }
public static Signal PolynomialLeadingCoefficient(Signal signal, Signal variable) { if (signal == null) { throw new ArgumentNullException("signal"); } IValueStructure degree = PolynomialDegree(signal, variable); IntegerValue iv = degree as IntegerValue; if (iv != null) { return(PolynomialCoefficient(signal, variable, (int)iv.Value)); } if (degree is NegativeInfinitySymbol) { return(IntegerValue.ConstantZero); } return(UndefinedSymbol.Constant); }
public abstract void PostNewValue(IValueStructure newValue);
protected ValueNode(IValueStructure initialValue) { _presentStructure = initialValue; }
public bool EqualsById(IValueStructure other) { return other != null && TypeId.Equals(other.TypeId); }
public StructureNotSupportedException(IValueStructure structure) : base() { this.structure = structure; }
public void ScheduleDelayedEvent(ISchedulable subject, IValueStructure value, TimeSpan delay) { GetCurrentScheduler().ScheduleDelayedEvent(subject, value, delay); }
public static Signal CreateSignal(IValueStructure value) { return(_cacheSignal2.GetInstance(value)); }
/// <summary> /// Request the scheduler to set a new value to this signal in the next delta-timestep. /// </summary> /// <remarks>The value is not set immediately. To propagate it to the <see cref="Value"/> property /// you need to simulate the model for at least one cycle or a time instant, by calling /// <see cref="Scheduler.SimulateInstant"/> or <see cref="Scheduler.SimulateFor"/>.</remarks> public override void PostNewValue(IValueStructure newValue) { throw new NotImplementedException(); }
/// <summary> /// Request the scheduler to set a new value to this signal with a specified simulation-time delay. /// </summary> /// <remarks>The value is not set immediately, To propagate it to the <see cref="Value"/> property /// you need to simulate the model for at least at least the specified delay, by calling /// <see cref="Scheduler.SimulateFor"/>.</remarks> /// <param name="delay">The simulation-time delay.</param> public override void PostNewValue(IValueStructure newValue, TimeSpan delay) { Service<ISimulationMediator>.Instance.ScheduleDelayedEvent(this, newValue, delay); }
/// <summary> /// Request the scheduler to set a new value to this signal in the next delta-timestep. /// </summary> /// <remarks>The value is not set immediately. To propagate it to the <see cref="Value"/> property /// you need to simulate the model for at least one cycle or a time instant, by calling /// <see cref="Scheduler.SimulateInstant"/> or <see cref="Scheduler.SimulateFor"/>.</remarks> public override void PostNewValue(IValueStructure newValue) { Service<ISimulationMediator>.Instance.ScheduleDeltaEvent(this, newValue); }
void ISignal_BuilderAdapter.BuilderSetValue(IValueStructure structure) { SetPresentValue(structure); }
public IValueStructure[] Evaluate(params IValueStructure[] inputs) { if(inputs == null) throw new ArgumentNullException("inputs"); if(inputs.Length != _inputs.Count) throw new System.ArgumentException("The count of inputs doesn't match the systems count of input signals.", "inputs"); for(int i = 0; i < inputs.Length; i++) _inputs[i].PostNewValue(inputs[i]); Service<ISimulationMediator>.Instance.SimulateInstant(); IValueStructure[] outputs = new IValueStructure[_outputs.Count]; for(int i = 0; i < outputs.Length; i++) outputs[i] = _outputs[i].Value; return outputs; }
public abstract void PostNewValue(IValueStructure newValue, TimeSpan delay);
public void ScheduleDeltaEvent(ISchedulable subject, IValueStructure value) { GetCurrentScheduler().ScheduleDeltaEvent(subject, value); }
public CurveSegment(Curve segment, TimeSpan begin, IValueStructure offset) { this.Segment = segment; this.Begin = begin; this.Offset = offset; }
public static Bus CreateBus(IValueStructure value) { return(_cacheBus2.GetInstance(value)); }
public void PushInputValue(int inputIndex, IValueStructure value) { _inputs[inputIndex].PostNewValue(value); }
public void PushInputValue(int inputIndex, IValueStructure value, TimeSpan delay) { _inputs[inputIndex].PostNewValue(value, delay); }
protected StructureNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context) { structure = (IValueStructure)info.GetValue("structure", typeof(IValueStructure)); }
internal Bus(IValueStructure value) : base(value) { Service<IMediator>.Instance.NotifyNewBusCreated(this); }
public SchedulerEventItem(ISchedulable subject, IValueStructure value, TimeSpan timeSpan) { _subject = subject; _value = value; _timeSpan = timeSpan; }
protected void PublishToOutputs(IValueStructure value, TimeSpan delay) { for(int i = 0; i < outputs.Length; i++) outputs[i].PostNewValue(value,delay); }
public static Signal DefineConstant(IValueStructure value) { Signal s = Binder.CreateSignal(value); s.Label = s.Value.ToString() + "_Constant"; s.EnableFlag(StdAspect.ConstantFlag); return s; }
public abstract bool Equals(IValueStructure other);
public void ScheduleDeltaEvent(ISchedulable subject, IValueStructure value) { _deltaEvents.Push(new SchedulerEventItem(subject, value, TimeSpan.Zero)); }
public Signal AddNamedSignal(string name, IValueStructure value) { if(_namedSignals == null) _namedSignals = new Dictionary<string, Signal>(); Signal signal = Binder.CreateSignal(value); AddSignal(signal); signal.Label = name; _namedSignals.Add(name, signal); return signal; }