protected override bool MustExplore(TraversalInfo ti) { ZingerStats.IncrementTransitionsCount(); if (!ti.IsFingerPrinted) return true; Fingerprint fp = ti.Fingerprint; if (GlobalStateTable.Contains(fp)) { var stateD = GlobalStateTable.GetStateData(fp); if (stateD.MagicBit == ti.MagicBit) { return false; } else { return true; } } else { return true; } }
public ExecutionState(StateImpl s, TraversalInfo predecessor, Via bt, bool MustFingerprint) : base(s, StateType.ExecutionState, predecessor, bt) { Debug.Assert(ProcessInfo != null && ProcessInfo.Length == NumProcesses); stateImpl = s; hasMultipleSuccessors = NumSuccessors() > 1; receipt = s.CheckIn(); if (!ZingerConfiguration.DoRandomSampling) { if (MustFingerprint) { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } else { this.fingerprint = null; this.IsFingerPrinted = false; } } }
public FrontierNode(TraversalInfo ti) { this.Bounds = new ZingerBounds(ti.zBounds.ExecutionCost, ti.zBounds.ChoiceCost); if (ZingerConfiguration.DoDelayBounding) { schedulerState = ti.ZingDBSchedState.Clone(true); } else if (ZingerConfiguration.DoPreemptionBounding) { preemptionBounding = ti.preemptionBounding.Clone(); } ti.IsFingerPrinted = true; TheTrace = ti.GenerateTrace(); }
public ExecutionState(StateImpl s, TraversalInfo predecessor, Via bt) : base(s, StateType.ExecutionState, predecessor, bt) { Debug.Assert(ProcessInfo != null && ProcessInfo.Length == NumProcesses); hasMultipleSuccessors = NumSuccessors() > 1; stateImpl = s; currProcess = 0; receipt = s.CheckIn(); #if true //dont fingerprint during random sampling if (!ZingerConfiguration.DoRandomSampling) { if (ZingerConfiguration.FingerprintSingleTransitionStates) { if (this.NumProcesses > 1) { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } else { // Fingerprint with probability p if (ZingerUtilities.rand.NextDouble() <= ZingerConfiguration.NonChooseProbability) { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } else { this.fingerprint = null; this.IsFingerPrinted = false; } } } else { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } } #endif }
public ChooseState(StateImpl s, TraversalInfo predecessor, Via bt) : base(s, StateType.ChooseState, predecessor, bt) { numChoices = s.NumChoices; hasMultipleSuccessors = s.NumChoices > 1; stateImpl = s; receipt = s.CheckIn(); if (!ZingerConfiguration.DoRandomSampling) { if (ZingerConfiguration.FingerprintSingleTransitionStates) { if (this.NumChoices > 1) { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } else { // Fingerprint with probability p if (ZingerUtilities.rand.NextDouble() <= ZingerConfiguration.NonChooseProbability) { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } else { this.fingerprint = null; this.IsFingerPrinted = false; } } } else { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } } }
public TerminalState(StateImpl s, TraversalInfo pred, Via bt, bool MustFingerprint) : base(s, StateType.TerminalState, pred, bt) { hasMultipleSuccessors = false; if (s.IsErroneous) { IsErroneous = true; Error = s.Exception; } else if (s.IsFailedAssumption) { IsFailedAssumption = true; Error = s.Exception; } else if (s.IsValidTermination) { IsValidTermination = true; } stateImpl = s; receipt = s.CheckIn(); if (MustFingerprint) { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } else { this.fingerprint = null; this.IsFingerPrinted = false; } }
protected override void Replay(TraversalInfo succ, Via bt) { throw new ArgumentException("cannot replay from a terminal node"); }
protected override void Replay(TraversalInfo succ, Via bt) { ViaExecute ve = (ViaExecute)bt; StateImpl s = this.reclaimState(); s.RunProcess(ve.ProcessExecuted); succ.deOrphanize(s); }
public TerminalState(StateImpl s, TraversalInfo pred, Via bt) : base(s, StateType.TerminalState, pred, bt) { hasMultipleSuccessors = false; if (s.IsErroneous) { IsErroneous = true; Error = s.Exception; } else if (s.IsFailedAssumption) { IsFailedAssumption = true; Error = s.Exception; } else if (s.IsValidTermination) { IsValidTermination = true; } stateImpl = s; receipt = s.CheckIn(); #if true if (ZingerConfiguration.FingerprintSingleTransitionStates) { // Fingerprint with probability p if (ZingerUtilities.rand.NextDouble() <= ZingerConfiguration.NonChooseProbability) { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } else { this.fingerprint = null; this.IsFingerPrinted = false; } } else { this.fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } #endif }
protected override bool MustExplore(TraversalInfo ti) { //Increment the number of transitions executed ZingerStats.IncrementTransitionsCount(); if (!ti.IsFingerPrinted) { return true; } Fingerprint fp = ti.Fingerprint; if (GlobalFrontierSet.Contains(fp) || ti.CurrentDepth > maxSearchDepth) { return false; } else { return true; } }
/// <summary> /// Constructor /// </summary> public FrontierSet(TraversalInfo startState) { if (!ZingerConfiguration.FrontierToDisk) { InMemoryCurrentGlobalFrontier = new ConcurrentQueue<FrontierNode>(); InMemoryNextGlobalFrontier = new ConcurrentDictionary<Fingerprint, FrontierNode>(); InMemoryNextGlobalFrontier.TryAdd(startState.Fingerprint, new FrontierNode(startState)); } else { currFrontierSet = new BlockingCollection<FrontierNode>(bufferSize); nextFrontierSet = new BlockingCollection<KeyValuePair<Fingerprint, FrontierNode>>(2 * bufferSize); nextFrontierSetHT = new HashSet<Fingerprint>(); readerWorkers = new Task[numOfRWThreads]; writerWorkers = new Task[numOfRWThreads]; counter = 0; currFrontierSet.Add(new FrontierNode(startState)); for (int i = 0; i < numOfRWThreads; i++) { File.Delete("i_" + i.ToString()); File.Delete("o_" + i.ToString()); } //put the start frontier onto disk var startFrontier = new FrontierNode(startState); Stream writeStream = File.Open("o_0", FileMode.Create); startFrontier.Serialize(writeStream); writeStream.Close(); } }
protected override void Replay(TraversalInfo succ, Via bt) { ViaChoose vc = (ViaChoose)bt; StateImpl s = this.reclaimState(); s.RunChoice(vc.ChoiceNumber); succ.deOrphanize(s); }
protected abstract void VisitState(TraversalInfo ti);
protected TraversalInfo(StateImpl s, StateType st, TraversalInfo pred, Via bt) { stateType = st; Via = bt; NumProcesses = s.NumProcesses; ProcessInfo = s.GetProcessInfo(); events = s.GetEvents(); exception = s.Exception; IsAcceptingState = s.IsAcceptingState; //initialize the plugin information. if (pred != null) { Predecessor = pred; CurrentDepth = pred.CurrentDepth + 1; zBounds = new ZingerBounds(pred.zBounds.ExecutionCost, pred.zBounds.ChoiceCost); zBounds.IncrementDepthCost(); doDelay = false; if (ZingerConfiguration.DoDelayBounding) { ZingDBSchedState = s.ZingDBSchedState; ZingDBScheduler = s.ZingDBScheduler; } else if (ZingerConfiguration.DoPreemptionBounding) { preemptionBounding = new ZingPreemptionBounding(ProcessInfo, NumProcesses, Predecessor.preemptionBounding.currentProcess); } if (ZingerConfiguration.DronacharyaEnabled || ZingerConfiguration.IsPluginEnabled) { ZingerPlugin = s.ZingerPlugin; ZingerPluginState = s.ZingerPluginState; } pred.Successor = this; MagicBit = pred.MagicBit; } else { zBounds = new ZingerBounds(); MagicBit = false; CurrentDepth = 0; if (ZingerConfiguration.DoDelayBounding) { ZingDBSchedState = s.ZingDBSchedState.Clone(false); ZingDBScheduler = s.ZingDBScheduler; } else if (ZingerConfiguration.DoPreemptionBounding) { preemptionBounding = new ZingPreemptionBounding(ProcessInfo, NumProcesses, 0); } if (ZingerConfiguration.DronacharyaEnabled || ZingerConfiguration.IsPluginEnabled) { ZingerPlugin = s.ZingerPlugin; ZingerPluginState = s.ZingerPluginState.Clone(); } } }
protected static TraversalInfo MakeTraversalInfo(StateImpl s, TraversalInfo pred, Via bt, bool MustFingerprint) { if (s.IsTerminalState) return new TerminalState(s, pred, bt, MustFingerprint); if (s.IsChoicePending) return new ChooseState(s, pred, bt, MustFingerprint); if (s.IsNormalState) return new ExecutionState(s, pred, bt, MustFingerprint); Debug.Fail("unexpected state type"); return null; }
public void Add(TraversalInfo ti) { //no need of adding to the frontier if the final choice bound is reached if (ZingerConfiguration.BoundChoices && ti.zBounds.ChoiceCost >= ZingerConfiguration.zBoundedSearch.FinalChoiceCutOff) { return; } Fingerprint fp = ti.Fingerprint; ti.IsFingerPrinted = true; if (ZingerConfiguration.FrontierToDisk) { if (!nextFrontierSetHT.Contains(fp)) { FrontierNode fNode = new FrontierNode(ti); counter++; nextFrontierSetHT.Add(fp); //Add the item into current next frontier blocking collection nextFrontierSet.Add(new KeyValuePair<Fingerprint, FrontierNode>(fp, fNode)); } } else { if (!InMemoryNextGlobalFrontier.ContainsKey(fp)) { FrontierNode fNode = new FrontierNode(ti); //add the item into in memory next frontier InMemoryNextGlobalFrontier.TryAdd(fp, fNode); } } }
private TraversalInfo SetMagicBit(TraversalInfo ti) { var fp = ti.Fingerprint; StateData sD = GlobalStateTable.GetStateData(fp); sD.MagicBit = true; GlobalStateTable.AddOrUpdate(fp, sD); return ti.SetMagicbit(); }
protected override void VisitState(TraversalInfo ti) { if (!ti.IsFingerPrinted) return; Fingerprint fp = ti.Fingerprint; StateData newD = new StateData(ti.MagicBit); GlobalStateTable.AddOrUpdate(fp, newD); }
public ChooseState(StateImpl s, TraversalInfo predecessor, Via bt, bool MustFingerprint) : base(s, StateType.ChooseState, predecessor, bt) { numChoices = s.NumChoices; stateImpl = s; hasMultipleSuccessors = s.NumChoices > 1; receipt = s.CheckIn(); if (!ZingerConfiguration.DoRandomSampling) { if (MustFingerprint) { fingerprint = s.Fingerprint; this.IsFingerPrinted = true; } else { this.fingerprint = null; this.IsFingerPrinted = false; } } }
protected override bool MustExplore(TraversalInfo ti) { //Increment the number of transitions executed ZingerStats.IncrementTransitionsCount(); if (!ti.IsFingerPrinted) { return true; } //else Fingerprint fp = ti.Fingerprint; //check if this is in the frontier //no need to explore frontier state if already explored if (GLobalFrontierSet.Contains(fp)) { return false; } else { if (!GlobalStateTable.Contains(fp)) { return true; } else { return false; } } }
protected abstract void Replay(TraversalInfo succ, Via bt);
private bool SearchStackContains(Stack<TraversalInfo> stack, TraversalInfo ti) { if (!ti.IsFingerPrinted) { return false; } Fingerprint fp = ti.Fingerprint; var contains = stack.Where(t => (t.IsFingerPrinted && t.Fingerprint == fp)).Count() > 0; return contains; }
protected abstract bool MustExplore(TraversalInfo ti);
protected override void VisitState(TraversalInfo ti) { throw new NotImplementedException(); }
private void Initialize() { //Fingerprint the start state. Fingerprint fp = startStateStateImpl.Fingerprint; CancelTokenZingExplorer = new CancellationTokenSource(); SafetyErrors = new ArrayList(); AcceptingCycles = new ArrayList(); lastErrorFound = ZingerResult.Success; StartStateTraversalInfo = GetTraversalInfoForTrace(null); }
protected override bool MustExplore(TraversalInfo ti) { throw new NotImplementedException(); }
protected override void VisitState(TraversalInfo ti) { if (!ti.IsFingerPrinted) return; Fingerprint fp = ti.Fingerprint; if (GLobalFrontierSet.Contains(fp) && !ZingerConfiguration.DoDelayBounding) { GLobalFrontierSet.Remove(fp); } if (!GlobalStateTable.Contains(fp)) { GlobalStateTable.AddOrUpdate(fp, null); } }
/// <summary> /// This function is called for each invocation of generateMotionPLan in the plugin /// </summary> /// <param name="terminalState"></param> public void GenerateMotionPlanFor(TraversalInfo terminalState) { var ex = terminalState.Exception as ZingerInvokeMotionPlanning; //add it to the list GenerateMotionPlanFor GMP = new Zing.GenerateMotionPlanFor(); GMP.startPosition = ex.startLocation; GMP.endPosition = ex.endLocation; GMP.obstacles = ex.obstacles.ToList(); lock (GenerateMotionPlans) { GenerateMotionPlans.Add(GMP); } }