System Architectures Blackboard Pattern
Jonathan Thaler
Department of Computer Science
1 / 31
System Architectures Blackboard Pattern Jonathan Thaler Department - - PowerPoint PPT Presentation
System Architectures Blackboard Pattern Jonathan Thaler Department of Computer Science 1 / 31 Blackboard Pattern Motivation Fire propagation in complex buildings is hard to detect and forecast, but exremely important for emergency plans. 2 /
1 / 31
2 / 31
3 / 31
4 / 31
5 / 31
6 / 31
7 / 31
8 / 31
9 / 31
10 / 31
11 / 31
12 / 31
13 / 31
14 / 31
15 / 31
16 / 31
17 / 31
18 / 31
19 / 31
20 / 31
1https://social.technet.microsoft.com/wiki/contents/articles/13461.
21 / 31
22 / 31
public class Blackboard { public ObservableCollection<IObject> CurrentObjects { get; set; } public Blackboard() { CurrentObjects = new ObservableCollection<IObject>(); } } public interface IObject { ObjectType Type { get; set; } string Name { get; set; } bool? IsThreat { get; set; } ProcessingStage Stage { get; set; } } public enum ObjectType { Unknown, Bird, Plane, Rocket } public enum ProcessingStage { Detected, Analysed, Identified, Actioned } 23 / 31
class Controller { Blackboard blackboard; List<IKnowledgeSource> KnowledgeSources = new List<IKnowledgeSource>(); List<IKnowledgeSource> OrderedKnowSrc; public Controller(Blackboard board) { blackboard = board; KnowledgeSources.Add( new SignalProcessor(DateTime.Now.Millisecond)); KnowledgeSources.Add(new ImageRecognition()); KnowledgeSources.Add(new PlaneIdentification()); KnowledgeSources.Add(new WarMachine()); OrderKnowledgeBases(); foreach (var ks in OrderedKnowSrc) ks.Configure(blackboard); } void tick(object sender, EventArgs e) { foreach (IKnowledgeSource ks in OrderedKnowSrc) if (ks.IsEnabled) ks.ExecuteAction(); }
24 / 31
public interface IKnowledgeSource { KnowledgeSourceType KSType { get; } KnowledgeSourcePriority Priority { get; } bool IsEnabled { get; } void Configure(Blackboard board); void Stop(); void ExecuteAction(); } public enum KnowledgeSourcePriority { Disabled, High, Normal } public enum KnowledgeSourceType { Detector, Analyser, Actioner }
25 / 31
26 / 31
27 / 31
class WarMachine : KnowledgeSourceBase { public override KnowledgeSourcePriority Priority { return KnowledgeSourcePriority.High; } public override bool IsEnabled { for (var ix = 0; ix < blackboard.CurrentObjects.Count(); ix++) { var obj = blackboard.CurrentObjects[ix]; if (obj.IsThreat != null && obj.IsThreat.Value && (obj.Stage != ProcessingStage.Actioned)) return true; } return false; } public override void ExecuteAction() { for (var ix = 0; ix < blackboard.CurrentObjects.Count(); ix++) { var obj = blackboard.CurrentObjects[ix] as IncomingObject; if (obj.IsThreat != null && obj.IsThreat.Value && (obj.Stage != ProcessingStage.Actioned)) { if (obj.MoveHitsTarget()) DestroyTarget(obj); } } } } 28 / 31
29 / 31
30 / 31
31 / 31