Skip to content

Commit 4015883

Browse files
committed
initial commit
1 parent 91164af commit 4015883

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+8452
-0
lines changed

ALANN Design.pdf

437 KB
Binary file not shown.

ALANNStreams.fsproj.CopyComplete.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Sorry, there was a problem downloading this file from OneDrive. Please try again.
2+
https://onedrive.live.com/?cid=6e1bfb540d21dcc7&id=6E1BFB540D21DCC7%21263540&action=Download&authKey=!AIwe5l9V-wEitPI

ALANNStreams/ALANNStreams.fsproj

+339
Large diffs are not rendered by default.

ALANNStreams/AnswerQueue.fs

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
(*
2+
* The MIT License
3+
*
4+
* Copyright 2018 The ALANN2018 authors.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*)
24+
25+
module AnswerQueue
26+
27+
open System.Diagnostics
28+
open C5
29+
open Types
30+
31+
//type AnswerQueue(n : int) =
32+
// let q = CircularQueue<Event>
33+
// let q = IntervalHeap<Belief>(n) :> IPriorityQueue<Belief>
34+
// let d = HashDictionary<Term, IPriorityQueueHandle<Belief>>() :>IDictionary<Term, IPriorityQueueHandle<Belief>>
35+
36+
// let maxSize = n
37+
38+
// interface IStore with
39+
// member x.Contains(term) = d.Contains term
40+
41+
// member x.Insert(event) =
42+
// //let cond = maxSize >= d.Count
43+
// //Debug.Assert(cond)
44+
45+
// if d.Count >= maxSize then
46+
// if event.TV.C >= q.FindMin().TV.C then
47+
// let (deleted, h) = q.DeleteMin()
48+
// let h = ref h
49+
// match d.Remove(deleted.Term, h ) with
50+
// | true -> ()
51+
// | false -> failwith "ConceptStore.Insert() : failed to remove on maxSize"
52+
53+
// q.Add(h, event) |> ignore
54+
// d.Add(event.Term, !h)
55+
// else
56+
// let h = ref null
57+
// q.Add(h, event) |> ignore
58+
// d.Add(event.Term, !h)
59+
60+
// member x.Update(event) =
61+
62+
// //if not(d.Contains(event.Term) ) then
63+
// // failwith "ConceptStore.Update() : conceptRef does not exist"
64+
65+
// let h = d.[event.Term]
66+
// q.[h] <- event
67+
68+
// member x.TryGetValue term =
69+
70+
// if d.Contains(term) then Some(q.[d.[term]])
71+
// else None
72+
73+
// member x.Clear() =
74+
75+
// d.Clear()
76+
// while not(q.IsEmpty) do
77+
// let (_,_) = q.DeleteMax()
78+
// ()
79+
80+
// member x.GetEnumerator() = q.GetEnumerator()
81+
82+
// member x.Count = d.Count
83+
84+
// //member x.DeleteMin() =
85+
// // let (deleted, h) = q.DeleteMin()
86+
// // let h = ref h
87+
// // match d.Remove(deleted, h ) with
88+
// // | true -> ()
89+
// // | false -> failwith "ConceptStore.DeleteMin() : failed to remove from dictionary"
90+
// // deleted
91+
92+
// member x.Beliefs() = q :> seq<Belief>

ALANNStreams/App.config

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<runtime>
4+
<Thread_UseAllCpuGroups enabled="true" />
5+
<GCCpuGroup enabled="true" />
6+
<gcServer enabled="true" />
7+
<gcConcurrent enabled="true" />
8+
</runtime>
9+
<startup>
10+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
11+
</startup>
12+
<appSettings>
13+
<add key="SAMPLE" value="1.0"/>
14+
</appSettings>
15+
</configuration>

ALANNStreams/AssemblyInfo.fs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace ALANNStreams.AssemblyInfo
2+
3+
open System.Reflection
4+
open System.Runtime.CompilerServices
5+
open System.Runtime.InteropServices
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[<assembly: AssemblyTitle("ALANNStreams")>]
11+
[<assembly: AssemblyDescription("")>]
12+
[<assembly: AssemblyConfiguration("")>]
13+
[<assembly: AssemblyCompany("")>]
14+
[<assembly: AssemblyProduct("ALANNStreams")>]
15+
[<assembly: AssemblyCopyright("Copyright © 2018")>]
16+
[<assembly: AssemblyTrademark("")>]
17+
[<assembly: AssemblyCulture("")>]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[<assembly: ComVisible(false)>]
23+
24+
// The following GUID is for the ID of the typelib if this project is exposed to COM
25+
[<assembly: Guid("82dfbdf2-260e-4b89-a76e-eab235bacda7")>]
26+
27+
// Version information for an assembly consists of the following four values:
28+
//
29+
// Major Version
30+
// Minor Version
31+
// Build Number
32+
// Revision
33+
//
34+
// You can specify all the values or you can default the Build and Revision Numbers
35+
// by using the '*' as shown below:
36+
// [<assembly: AssemblyVersion("1.0.*")>]
37+
[<assembly: AssemblyVersion("1.0.0.0")>]
38+
[<assembly: AssemblyFileVersion("1.0.0.0")>]
39+
40+
do
41+
()

ALANNStreams/Containers/EventStore.fs

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
(*
2+
* The MIT License
3+
*
4+
* Copyright 2018 The ALANN2018 authors.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*)
24+
25+
module EventStore
26+
27+
open C5
28+
open Types
29+
open System.Collections.Generic
30+
31+
//type IEventStore =
32+
// abstract GetAll : unit -> IList<IPriorityQueueHandle<Event>>
33+
// abstract Get : IPriorityQueueHandle<Event> -> Event
34+
// abstract Update : IPriorityQueueHandle<Event> * Event -> unit
35+
// abstract Count : int
36+
// abstract Push : Event -> unit
37+
// abstract Pop : unit -> IPriorityQueueHandle<Event> * Event
38+
39+
40+
type IEventStore =
41+
abstract GetAll : unit -> Event array
42+
abstract Count : int
43+
abstract Push : Event -> unit
44+
abstract Reset : unit -> unit
45+
46+
type Comparer() =
47+
interface IComparer<Event> with
48+
49+
member this.Compare(x, y) =
50+
let now = SystemTime()
51+
let age e =
52+
let age = float32((now - e.Stamp.Created))
53+
age / (age + 10.0f)
54+
let a = x.AV.STI * age x * match x.TV with | Some {F = f; C = c} -> c | None -> 1.0f
55+
let b = y.AV.STI * age y * match y.TV with | Some {F = f; C = c} -> c | None -> 1.0f
56+
//let a = x.AV.STI
57+
//let b = y.AV.STI
58+
59+
a.CompareTo(b)
60+
61+
let eventComparer = Comparer()
62+
63+
//type EventEqualityComparer() =
64+
// interface IEqualityComparer<Event> with
65+
66+
// member this.Equals(x, y) =
67+
// x.Term = y.Term
68+
69+
// member this.GetHashCode(x) = x.GetHashCode()
70+
71+
//let eventEqualityComparer = EventEqualityComparer()
72+
73+
type EventStore(n : int) =
74+
let q = new TreeSet<Event>(eventComparer) :> IIndexedSorted<Event>
75+
76+
let maxSize = n
77+
78+
interface IEventStore with
79+
member x.GetAll() = q.ToArray()
80+
81+
member x.Reset() = q.Clear()
82+
83+
member x.Push(event) =
84+
if q.Count >= maxSize then
85+
if event.AV.STI > q.FindMin().AV.STI then
86+
q.DeleteMin() |> ignore
87+
q.Add(event) |> ignore
88+
else
89+
q.Add(event) |> ignore
90+
91+
member x.Count = q.Count
92+
93+
//type EventStore(n : int) =
94+
// let q = IntervalHeap<Event>(n, eventComparer) :> IPriorityQueue<Event>
95+
// let handles = new ArrayList<IPriorityQueueHandle<Event>>(n) :> IList<IPriorityQueueHandle<Event>>
96+
97+
// let maxSize = n
98+
99+
// interface IEventStore with
100+
// member x.GetAll() = handles
101+
102+
// member x.Get(h) = q.[h]
103+
104+
// member x.Update(h, e) =
105+
// q.[h] <- e
106+
107+
// member x.Count = q.Count
108+
109+
// member x.Push(event) =
110+
// if q.Count >= maxSize then
111+
// let (_, h) = q.DeleteMin()
112+
// let h = ref h
113+
// q.Add(h, event)|> ignore
114+
// else
115+
// let h = ref null
116+
// q.Add(h, event) |> ignore
117+
// handles.Add(!h) |> ignore
118+
119+
// member x.Pop() =
120+
// let h = ref null
121+
// let e = q.FindMax(h)
122+
// (!h, e)
123+

ALANNStreams/Containers/Store.fs

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
(*
2+
* The MIT License
3+
*
4+
* Copyright 2018 The ALANN2018 authors.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*)
24+
25+
module Store
26+
27+
open System.Diagnostics
28+
open C5
29+
open Types
30+
31+
type Store(n : int) =
32+
let q = IntervalHeap<Belief>(n) :> IPriorityQueue<Belief>
33+
let d = HashDictionary<Key, IPriorityQueueHandle<Belief>>() :>IDictionary<Key, IPriorityQueueHandle<Belief>>
34+
35+
let maxSize = n
36+
37+
interface IStore with
38+
member x.Contains(term) = d.Contains term
39+
40+
member x.Insert(event) =
41+
//let cond = maxSize >= d.Count
42+
//Debug.Assert(cond)
43+
44+
if d.Count >= maxSize then
45+
if event.TV.C >= q.FindMin().TV.C then
46+
let (deleted, h) = q.DeleteMin()
47+
let h = ref h
48+
match d.Remove((deleted.Term, deleted.Stamp.Evidence), h ) with
49+
| true -> ()
50+
| false -> failwith "ConceptStore.Insert() : failed to remove on maxSize"
51+
52+
q.Add(h, event) |> ignore
53+
d.Add((event.Term, event.Stamp.Evidence), !h)
54+
else
55+
let h = ref null
56+
q.Add(h, event) |> ignore
57+
d.Add((event.Term, event.Stamp.Evidence), !h)
58+
59+
member x.Update(event) =
60+
61+
//if not(d.Contains(event.Term) ) then
62+
// failwith "ConceptStore.Update() : conceptRef does not exist"
63+
64+
let h = d.[(event.Term, event.Stamp.Evidence)]
65+
q.[h] <- event
66+
67+
member x.TryGetValue term =
68+
69+
if d.Contains(term) then Some(q.[d.[term]])
70+
else None
71+
72+
member x.Clear() =
73+
74+
d.Clear()
75+
while not(q.IsEmpty) do
76+
let (_,_) = q.DeleteMax()
77+
()
78+
79+
member x.GetEnumerator() = q.GetEnumerator()
80+
81+
member x.Count = d.Count
82+
83+
//member x.DeleteMin() =
84+
// let (deleted, h) = q.DeleteMin()
85+
// let h = ref h
86+
// match d.Remove(deleted, h ) with
87+
// | true -> ()
88+
// | false -> failwith "ConceptStore.DeleteMin() : failed to remove from dictionary"
89+
// deleted
90+
91+
member x.Beliefs() = q :> seq<Belief>

0 commit comments

Comments
 (0)