Z3
 
Loading...
Searching...
No Matches
Statistics.cs
Go to the documentation of this file.
1/*++
2Copyright (c) 2012 Microsoft Corporation
3
4Module Name:
5
6 Statistics.cs
7
8Abstract:
9
10 Z3 Managed API: Statistics
11
12Author:
13
14 Christoph Wintersteiger (cwinter) 2012-03-22
15
16Notes:
17
18--*/
19
20using System;
21using System.Diagnostics;
22namespace Microsoft.Z3
23{
24
25 using Z3_context = System.IntPtr;
26 using Z3_stats = System.IntPtr;
30 public class Statistics : Z3Object
31 {
36 public class Entry
37 {
41 readonly public string Key;
45 public uint UIntValue { get { return m_uint; } }
49 public double DoubleValue { get { return m_double; } }
53 public bool IsUInt { get { return m_is_uint; } }
57 public bool IsDouble { get { return m_is_double; } }
58
62 public string Value
63 {
64 get
65 {
66
67 if (IsUInt)
68 return m_uint.ToString();
69 else if (IsDouble)
70 return m_double.ToString();
71 else
72 throw new Z3Exception("Unknown statistical entry type");
73 }
74 }
75
79 public override string ToString()
80 {
81 return Key + ": " + Value;
82 }
83
84 #region Internal
85 readonly private bool m_is_uint = false;
86 readonly private bool m_is_double = false;
87 readonly private uint m_uint = 0;
88 readonly private double m_double = 0.0;
89 internal Entry(string k, uint v)
90 {
91 Key = k;
92 m_is_uint = true;
93 m_uint = v;
94 }
95 internal Entry(string k, double v)
96 {
97 Key = k;
98 m_is_double = true;
99 m_double = v;
100 }
101 #endregion
102 }
103
107 public override string ToString()
108 {
109 return Native.Z3_stats_to_string(Context.nCtx, NativeObject);
110 }
111
115 public uint Size
116 {
117 get { return Native.Z3_stats_size(Context.nCtx, NativeObject); }
118 }
119
123 public Entry[] Entries
124 {
125 get
126 {
127 return NativeEntries(Context.nCtx, NativeObject);
128 }
129 }
130
131 internal static Entry[] NativeEntries(Z3_context ctx, Z3_stats stats)
132 {
133 uint n = Native.Z3_stats_size(ctx, stats);
134 Entry[] res = new Entry[n];
135 for (uint i = 0; i < n; i++)
136 {
137 Entry e;
138 string k = Native.Z3_stats_get_key(ctx, stats, i);
139 if (Native.Z3_stats_is_uint(ctx, stats, i) != 0)
140 e = new Entry(k, Native.Z3_stats_get_uint_value(ctx, stats, i));
141 else if (Native.Z3_stats_is_double(ctx, stats, i) != 0)
142 e = new Entry(k, Native.Z3_stats_get_double_value(ctx, stats, i));
143 else
144 throw new Z3Exception("Unknown data entry value");
145 res[i] = e;
146 }
147 return res;
148 }
149
153 public string[] Keys
154 {
155 get
156 {
157
158 uint n = Size;
159 string[] res = new string[n];
160 for (uint i = 0; i < n; i++)
161 res[i] = Native.Z3_stats_get_key(Context.nCtx, NativeObject, i);
162 return res;
163 }
164 }
165
170 public Entry this[string key]
171 {
172 get
173 {
174 uint n = Size;
175 Entry[] es = Entries;
176 for (uint i = 0; i < n; i++)
177 if (es[i].Key == key)
178 return es[i];
179 return null;
180 }
181 }
182
183 #region Internal
184 internal Statistics(Context ctx, IntPtr obj)
185 : base(ctx, obj)
186 {
187 Debug.Assert(ctx != null);
188 }
189
190 internal override void IncRef(IntPtr o)
191 {
192 Native.Z3_stats_inc_ref(Context.nCtx, o);
193 }
194
195 internal override void DecRef(IntPtr o)
196 {
197 lock (Context)
198 {
199 if (Context.nCtx != IntPtr.Zero)
200 Native.Z3_stats_dec_ref(Context.nCtx, o);
201 }
202 }
203 #endregion
204 }
205}
The main interaction with Z3 happens via the Context.
Definition Context.cs:34
Statistical data is organized into pairs of [Key, Entry], where every Entry is either a DoubleEntry o...
Definition Statistics.cs:37
double DoubleValue
The double-value of the entry.
Definition Statistics.cs:49
readonly string Key
The key of the entry.
Definition Statistics.cs:41
uint UIntValue
The uint-value of the entry.
Definition Statistics.cs:45
bool IsDouble
True if the entry is double-valued.
Definition Statistics.cs:57
bool IsUInt
True if the entry is uint-valued.
Definition Statistics.cs:53
override string ToString()
The string representation of the Entry.
Definition Statistics.cs:79
string Value
The string representation of the entry's value.
Definition Statistics.cs:63
Objects of this class track statistical information about solvers.
Definition Statistics.cs:31
string[] Keys
The statistical counters.
uint Size
The number of statistical data.
override string ToString()
A string representation of the statistical data.
Entry[] Entries
The data entries.
The exception base class for error reporting from Z3.
Internal base class for interfacing with native Z3 objects. Should not be used externally.
Definition Z3Object.cs:33
Context Context
Access Context object.
Definition Z3Object.cs:111
System.IntPtr Z3_context
Definition Context.cs:29
System.IntPtr Z3_stats