Repository navigation
Expand file tree
/
Copy pathComparableEvent.cs
More file actions
220 lines (203 loc) · 6.06 KB
/
Copy pathComparableEvent.cs
File metadata and controls
220 lines (203 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//Copyright (C) 2005 Richard J. Northedge
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//This file is based on the ComparableEvent.java source file found in the
//original java implementation of MaxEnt. That source file contains the following header:
// Copyright (C) 2001 Jason Baldridge and Gann Bierner
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
using System;
using System.Text;
namespace BotSharp.Models
{
/// <summary>
/// A Maximum Entropy event representation which we can use to sort based on the
/// predicates indexes contained in the events.
/// </summary>
/// <author>
/// Jason Baldridge
/// </author>
/// <author>
/// Richard J. Northedge
/// </author>
/// <version>
/// based on ComparableEvent.java, $Revision: 1.2 $, $Date: 2001/12/27 19:20:26 $
/// </version>
public class ComparableEvent : IComparable<ComparableEvent>
{
private int mOutcome;
private int[] mPredicateIndexes ;
private int mSeenCount = 1;
/// <summary>
/// The outcome ID of this event.
/// </summary>
public int Outcome
{
get
{
return mOutcome;
}
set
{
mOutcome = value;
}
}
/// <summary>
/// Returns an array containing the indexes of the predicates in this event.
/// </summary>
/// <returns>
/// Integer array of predicate indexes.
/// </returns>
public int[] GetPredicateIndexes()
{
return mPredicateIndexes;
}
/// <summary>
/// Sets the array containing the indices of the predicates in this event.
/// </summary>
/// <param name="predicateIndexes">
/// Integer array of predicate indexes.
/// </param>
public void SetPredicateIndexes(int[] predicateIndexes)
{
mPredicateIndexes = predicateIndexes;
}
/// <summary>
/// The number of times this event
/// has been seen.
/// </summary>
public int SeenCount
{
get
{
return mSeenCount;
}
set
{
mSeenCount = value;
}
}
/// <summary>
/// Constructor for the ComparableEvent.
/// </summary>
/// <param name="outcome">
/// The ID of the outcome for this event.
/// </param>
/// <param name="predicateIndexes">
/// Array of indexes for the predicates in this event.
/// </param>
public ComparableEvent(int outcome, int[] predicateIndexes)
{
mOutcome = outcome;
System.Array.Sort(predicateIndexes);
mPredicateIndexes = predicateIndexes;
}
/// <summary>
/// Implementation of the IComparable interface.
/// </summary>
/// <param name="eventToCompare">
/// ComparableEvent to compare this event to.
/// </param>
/// <returns>
/// A value indicating if the compared object is smaller, greater or the same as this event.
/// </returns>
public virtual int CompareTo(ComparableEvent eventToCompare)
{
if (mOutcome < eventToCompare.Outcome)
{
return - 1;
}
else if (mOutcome > eventToCompare.Outcome)
{
return 1;
}
int smallerLength = (mPredicateIndexes .Length > eventToCompare.GetPredicateIndexes().Length ? eventToCompare.GetPredicateIndexes().Length : GetPredicateIndexes().Length);
for (int currentIndex = 0; currentIndex < smallerLength; currentIndex++)
{
if (mPredicateIndexes [currentIndex] < eventToCompare.GetPredicateIndexes()[currentIndex])
{
return - 1;
}
else if (mPredicateIndexes [currentIndex] > eventToCompare.GetPredicateIndexes()[currentIndex])
{
return 1;
}
}
if (mPredicateIndexes .Length < eventToCompare.GetPredicateIndexes().Length)
{
return - 1;
}
else if (mPredicateIndexes .Length > eventToCompare.GetPredicateIndexes().Length)
{
return 1;
}
return 0;
}
/// <summary>
/// Tests if this event is equal to another object.
/// </summary>
/// <param name="o">
/// Object to test against.
/// </param>
/// <returns>
/// True if the objects are equal.
/// </returns>
public override bool Equals (object o)
{
if (!(o is ComparableEvent))
{
return false;
}
return (this.CompareTo(o as ComparableEvent)== 0);
}
/// <summary>
/// Provides a hashcode for storing events in a dictionary or hashtable.
/// </summary>
/// <returns>
/// A hashcode value.
/// </returns>
public override int GetHashCode()
{
return this.ToString().GetHashCode();
}
/// <summary>
/// Override to provide a succint summary of the ComparableEvent object.
/// </summary>
/// <returns>
/// string representation of the ComparableEvent object.
/// </returns>
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
for (int currentIndex = 0; currentIndex < mPredicateIndexes.Length; currentIndex++)
{
stringBuilder.Append(" ").Append(mPredicateIndexes [currentIndex]);
}
return stringBuilder.ToString();
}
}
}