public void GraphShouldTriggerEventOnExistingCycleBecomingNegative( ) { var graph = new Graph(CryptoExchangeId.Binance); var count = 0; ICycle <Node> lastCycle = null; graph.NegativeCycleFound += (g, cycle) => { ++count; lastCycle = cycle; return(Task.CompletedTask); }; Assert.Zero(count); Assert.IsNull(lastCycle); graph.UpsertEdge("A", "B", 0m); graph.UpsertEdge("A", "B", 1m); graph.UpsertEdge("B", "C", 1m); graph.UpsertEdge("C", "A", 0.5m); Assert.Zero(count); Assert.IsNull(lastCycle); graph.UpsertEdge("C", "A", 1.5m); Assert.AreEqual(count, 1); Assert.IsNotNull(lastCycle); Assert.True(IsCyclicEquivalent(lastCycle, "A", "B", "C", "A")); }
public bool AddCycle(string from, string to, ICycle <TNode> cycle) { if (!data.TryGetValue(from, out var dict)) { data[from] = new ConcurrentDictionary <string, ImmutableHashSet <ICycle <TNode> > > { [to] = ImmutableHashSet <ICycle <TNode> > .Empty.Add(cycle) }; return(true); } if (dict.TryGetValue(to, out var storedCycles)) { var builder = storedCycles.ToBuilder( ); var result = builder.Add(cycle); dict[to] = builder.ToImmutable( ); return(result); } dict[to] = ImmutableHashSet <ICycle <TNode> > .Empty.Add(cycle); return(true); }
public AutomataFiniteAbstract(string ID, ICycle cycle) : base(ID, cycle) { _states = FactoryAutomataFinite.GenerateAutomataStateCollection(); _transitions = FactoryAutomataFinite.GenerateAutomataTransitionCollection(); _processor = GenerateProcessor(); }
public void OnInputClicked(InputClickedEventData eventData) { mCycleComp = CycleObject.GetComponent <ICycle>(); if (mCycleComp != null) { mCycleComp.MoveNext(); } }
private static bool IsCyclicEquivalent <TNode> (ICycle <TNode> cycle, params string[] symbols) where TNode : INode { return(cycle .Path .Select(x => x.Symbol) .ToList( ) .IsCyclicEquivalent(symbols)); }
private void updateCycleStatus(ICycle cycle) { if (Finalized) { removeCycleHooks(); } else // means that a Final state has been reached { EvalStep(); } }
/// <summary> /// Runs <see cref="ICycle"/>, originating, executing and terminating it. /// </summary> /// <param name="cycle"> /// <see cref="ICycle"/> to run. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="cycle"/> is null. /// </exception> public static void Run(this ICycle cycle) { if (cycle is null) { throw new ArgumentNullException(nameof(cycle)); } using (cycle.Span.Open()) { cycle.Execution.Execute(); } }
/// <summary> /// Binds <see cref="ICycle"/> to <see cref="ISpan"/>. /// </summary> /// <param name="cycle"> /// <see cref="ICycle"/> to be bound to <paramref name="span"/>. /// </param> /// <param name="span"> /// <see cref="ISpan"/> to bind <paramref name="cycle"/>. /// </param> /// <returns> /// <see cref="ICycle"/> bound. /// </returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="cycle"/> is null. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="span"/> is null. /// </exception> public static ICycle In(this ICycle cycle, ISpan span) { if (cycle is null) { throw new ArgumentNullException(nameof(cycle)); } if (span is null) { throw new ArgumentNullException(nameof(span)); } return(new Cycle(span, cycle)); }
/// <summary> /// Setup the CycleData list /// </summary> private void Start() { mCycleList = new List <CycleData>(); for (int i = 0; i < CycleControllers.Length; ++i) { ICycle cycle = CycleControllers[i].GetComponent <ICycle>(); if (cycle != null) { CycleData data = new CycleData(); data.Controller = cycle; data.Index = cycle.Index; mCycleList.Add(data); } } }
/// <summary> /// Binds <see cref="ICycle"/> to <see cref="IOrigination"/> and <see cref="ITermination"/>. /// </summary> /// <param name="cycle"> /// <see cref="ICycle"/> to be bound to <paramref name="origination"/> and <paramref name="termination"/>. /// </param> /// <param name="origination"> /// <see cref="IOrigination"/> to bind to <see cref="ICycle"/>. /// </param> /// <param name="termination"> /// <see cref="ITermination"/> to bind to <see cref="ICycle"/>. /// </param> /// <returns> /// <see cref="ICycle"/> bound. /// </returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="cycle"/> is null. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="origination"/> is null. /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="termination"/> is null. /// </exception> public static ICycle Between(this ICycle cycle, IOrigination origination, ITermination termination) { if (cycle is null) { throw new ArgumentNullException(nameof(cycle)); } if (origination is null) { throw new ArgumentNullException(nameof(origination)); } if (termination is null) { throw new ArgumentNullException(nameof(termination)); } return(cycle.In(origination.To(termination))); }
// Use this for initialization void Awake() { if (CycleHost == null) { CycleHost = this.gameObject; Debug.Log("CycleHost was set to self by default"); } mTextMesh = GetComponent <TextMesh>(); mText = GetComponent <Text>(); if (mTextMesh == null && mText == null) { Debug.LogError("There are no Text Components on this <GameObject:" + this.gameObject.name + ">"); } mCycleHost = CycleHost.GetComponent <ICycle>(); }
protected void UpdateCycleStatus(ICycle cycle) { try { if (InvokeRequired) { this.Invoke(new UpdateCycleStatusDelegate(UpdateCycleStatus), new Object[] { cycle }); } else { UpdateTextBox(textBoxTimeEvolution, DateTime.UtcNow.ToString("o"), cycle.CyclePos); } } catch {} }
public void Explore(ICycle cycle, string description) { Cycle = cycle; Description = description; Start(); }
public AutomataFiniteTimmed(string ID, ICycle cycle) : base(ID, cycle) { }
bool IEquatable <ICycle <TNode> > .Equals(ICycle <TNode> other) => other != null && other.Path.IsCyclicEquivalent(Path);
public void ListProperties(ICycle cycle) { Console.WriteLine(cycle.TypeOfCycle); }
protected void updateCycleStatus(ICycle cycle) { TesterLog("Cycle value", DateTime.UtcNow.ToString("o"), cycle.Clock.Ticks); if (_automata == null) { return; }; if (_automata.Finalized) { FactoryClockEvolution.Evolution.Stop(); //ClockAtomicFactory.DestroyAtomicClock(_cycle.Clock); TesterLog(_automata.ID, _automata.Debugger.ShortDebug); } //else //{ // Thread.Sleep(Configuration.EffectiveInterval); //} }
public AutomataFiniteContinuous(string ID, ICycle cycle) : base(ID, cycle) { }
public AutomataProcessorFiniteTimmed(ICycle cycle) : base(cycle) { }
protected void updateCycleStatus(ICycle cycle) { TesterLog("Time Evolution Iteration before", _iterator, FactoryClockAtomic.ClockAtomicDefault.Ticks); TesterLog("Cycle value", cycle.CyclePos + " of " + cycle.CycleLenght); _iterator++; if (_iterator >= maxIterations) { //ClockEvolutionFactory.Evolution.Stop(); _cycle31.Dispose(); _cycle21.Dispose(); } TesterLog("Time Evolution Iteration after", _iterator, FactoryClockAtomic.ClockAtomicDefault.Ticks); }
public static IAutomataProcessorFinite GenerateAutomataProcessor(ICycle cycle) { return new AutomataProcessorFiniteBasic(cycle); }
protected override void PrepareExecution() { base.PrepareExecution(); _iterator = 0; _explorerRepository = ExplorerClockFactory.generateClockRepositoryExplorer(ManagerUI.MainWindow); _explorerCycle31 = ExplorerCycleFactory.generateCycleExplorer(ManagerUI.MainWindow); _explorerCycle21 = ExplorerCycleFactory.generateCycleExplorer(ManagerUI.MainWindow); _cycle31 = FactoryCycle.GenerateCycle(ID, 3, 1); _cycle21 = FactoryCycle.GenerateCycle(ID, 2, 1); }
/// <inheritdoc/> public override int Contribution(int u, Graph g, ICycle cycle, BitArray cyclic) { if (!cyclic[u]) { return(-1); } IAtom atom = g.GetAtom(u); Element elem = atom.Element; // the element isn't allow to be aromatic (Daylight spec) if (!elem.IsAromatic(Element.AromaticSpecification.Daylight) || elem == Element.Unknown) { return(-1); } // count cyclic and acyclic double bonds int nCyclic = 0, nAcyclic = 0; int deg = g.Degree(u) + g.ImplHCount(u); Edge acyclic = null; int sum = 0; foreach (var e in g.GetEdges(u)) { sum += e.Bond.Order; if (e.Bond.Order == 2) { if (!cyclic[e.Other(u)]) { nAcyclic++; acyclic = e; } else { nCyclic++; } } } int charge = atom.Charge; int valence = sum + g.ImplHCount(u); if (!atom.Element.Verify(valence, charge)) { return(-1); } if (deg > 3) { return(-1); } if (nCyclic > 1) { return(-1); } if (nCyclic == 1 && nAcyclic == 1) { // [P|N](=O)(=*)* - note arsenic not allowed if ((elem == Nitrogen || elem == Phosphorus) && g.GetAtom(acyclic.Other(u)).Element == Oxygen) { return(1); } return(-1); } else if (nCyclic == 1 && nAcyclic == 0) { // any element (except Arsenic) with a single cyclic double bond // contributes 1 p electron return(elem != Arsenic ? 1 : -1); } else if (nCyclic == 0 && nAcyclic == 1) { // a cyclic exo-cyclic double bond - how many electrons determine // by AcyclicContribution() return(AcyclicContribution(atom, g.GetAtom(acyclic.Other(u)), charge)); } else if (nCyclic == 0 && nAcyclic == 0 && charge > -3) { // no double bonds - do we have any lone pairs to contribute? int v = Valence(elem, charge); if (v - sum >= 2 && charge <= 0) { return(2); } if (charge == 1 && atom.Element == Carbon) { return(0); } } return(-1); }
/// <summary> /// The number p electrons dominated by the atom label at vertex 'u' in the /// 'cycle' of the graph 'g'. Additionally the 'cyclic' bit set indicates the /// vertices are members of any cycle. /// /// Depending on the perception method the 'cycle' may not be known in which /// case a runtime error will be thrown if it is needed for determining the /// donation. The cycle will be Unknown if the method use the donation model /// builds up the cycle iteratively counting the number of p electrons. /// </summary> /// <param name="u">the vertex under consideration</param> /// <param name="g">the graph the vertex is referring to</param> /// <param name="cycle"> the cycle under consideration</param> /// <param name="cyclic">all cyclic vertices</param> /// <returns>the number of p electrons contributed to if the element or -1 if /// the vertex should not be used</returns> public abstract int Contribution(int u, Graph g, ICycle cycle, BitArray cyclic);
public AutomataGenericAbstract(string ID, ICycle cycle) : base() { _cycle = cycle; _id = ID; }
internal Cycle(ISpan span, ICycle cycle) { this.span = span; this.cycle = cycle; }
public AutomataProcessorFiniteBasic(ICycle cycle) : base(cycle) { }
public AutomataProcessorFiniteAbstract(ICycle cycle) : base() { _cycle = cycle; }
protected override void PrepareExecution() { base.PrepareExecution(); _cycle = FactoryCycle.GenerateCycle(ID,1,1); _cycle.OnCycleTriggerEvent += new EventHandlerCycleTriggerEvent(updateCycleStatus); _explorer = ExplorerCycleFactory.generateCycleExplorer(ManagerUI.MainWindow); _explorer.Explore(_cycle, "Cycle Exploration Description"); _automata = FactoryAutomataFinite.GenerateAutomata("Sample Automata", _cycle); _automata.OnStateEnter += new FiniteAutomataStateEvent(eventStateEnter); _automata.OnStateExit += new FiniteAutomataStateEvent(eventStateExit); _automata.OnTransition += new FiniteAutomataTransitionEvent(eventTransition); _automata.OnEval += new FiniteAutomataTransitionConditionEvent(eventCondition); IAutomataStateFinite _state_Initial = FactoryAutomataFinite.GenerateAutomataStateInitial(_automata, eventExecuteAction); IAutomataStateFinite _state_Test = FactoryAutomataFinite.GenerateAutomataStateGeneric(_automata, "Test", eventExecuteAction); IAutomataStateFinite _state_Final = FactoryAutomataFinite.GenerateAutomataStateFinal(_automata, eventExecuteAction); IAutomataTransitionFinite _transition_Initial_Test = FactoryAutomataFinite.GenerateAutomataTransition(_state_Initial, _state_Test, FactoryAutomataFinite.TransitionConditionAlways); IAutomataTransitionFinite _transition_Test_Final = FactoryAutomataFinite.GenerateAutomataTransition(_state_Test, _state_Final, FactoryAutomataFinite.TransitionConditionAlways); }
public ProtocolAutomataAbstract(string ID, ICycle cycle) : base(ID, cycle) { }
public static IAutomataFinite GenerateAutomata(string ID, ICycle cycle) { return new AutomataFiniteContinuous(ID, cycle); //return new FiniteAutomataTimmed(ID, cycle); }
public static bool IsCyclicEquivalent <TNode> (this ICycle <TNode> cycle1, ICycle <TNode> cycle2) where TNode : INode => IsCyclicEquivalent(cycle1.Path, cycle2.Path);