summaryrefslogtreecommitdiff
path: root/SA_POP/SANet/SANet_Types.h
blob: 443ba67efe1d147a8cf6eb12ffe87270fff399d0 (plain)
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// -*- C++ -*-
// $Id$

//=============================================================================
/**
 * @file  SANet_Types.h
 *
 * This file contains the definitions of types used throughout SANet.
 *
 * @author  John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
 */
//=============================================================================

#ifndef SANET_TYPES_H_
#define SANET_TYPES_H_

#include <string>
#include <sstream>
#include <set>
#include <list>
#include <map>
#include <utility>


#if !defined (SANET_STANDALONE)

#include "SA_POP/SA_POP_Types.h"

namespace SANet {
  /// Type of a node id (tasks and conditions).
  /// (must be > 0 and unique across all tasks *and* conditions).
  typedef SA_POP::NodeID NodeID;

  /// Type of a condition id.
  /// (must be > 0 and unique across all tasks *and* conditions).
  typedef SA_POP::CondID CondID;

  /// Type of a condition value.
  typedef SA_POP::CondValue CondValue;

  /// Type of a condition kind/type.
  typedef SA_POP::CondKind CondKind;

  /// Type of a condition.
  typedef SA_POP::Condition Condition;

  /// Type of a task ID.
  /// (must be > 0 and unique across all tasks *and* conditions).
  typedef SA_POP::TaskID TaskID;

  /// NULL task ID (for unknown/uninitialized tasks).
  const TaskID NULL_TASK_ID = SA_POP::NULL_TASK_ID;

  /// NULL condition ID (for unknown/uninitialized conditions).
  const CondID NULL_COND_ID = SA_POP::NULL_TASK_ID;

  /// Type of a port id.
  typedef SA_POP::PortID PortID;

  /// Type of an expected utility calculation (basetype for others).
  /// (N.B. this must be a double or float to handle [0,1] range probabilities
  /// and multiplication factors).
  typedef SA_POP::EUCalc EUCalc;
          
  /// Type of a condition utility.
  typedef SA_POP::Utility Utility;

  /// Type of a probability.
  typedef SA_POP::Probability Probability;

  /// Type of a (precondition or effect) link weight.
  typedef SA_POP::LinkWeight LinkWeight;

  /// Type of a task cost.
  typedef SA_POP::TaskCost TaskCost;

  /// Type of a multiplicative factor (e.g. attenuation factor).
  typedef SA_POP::MultFactor MultFactor;

  /// Type of a precondition link.
  typedef SA_POP::PrecondLink PrecondLink;

  /// Type of an effect link.
  typedef SA_POP::EffectLink EffectLink;

  /// Type of a pair of ports for a link.
  typedef SA_POP::LinkPorts LinkPorts;

  /// Type of a list of tasks.
  typedef SA_POP::TaskList TaskList;

  /// Type of a set of goal conditions with associated utilities.
  typedef SA_POP::GoalMap GoalMap;

  /// Type of a set of tasks with associated expected utilities.
  typedef SA_POP::TaskEUMap TaskEUMap;

  /// Type of a set of conditions (condition & value).
  typedef SA_POP::CondSet CondSet;

  /// Type of a set of task ids.
  typedef SA_POP::TaskSet TaskSet;

    /// Type of duration
  typedef SA_POP::TimeValue TimeValue;

    /// NULL time (for unknown or unconstrained times).
  #define NULL_TIME -1

  inline std::string to_string(int x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(int) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(long x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(long) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(unsigned long x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(unsigned long) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(double x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(double) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(float x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(float) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(CondKind x)
  {
    std::ostringstream o;
    std::string x_str = "";

    switch (x) {
      case SA_POP::DATA :
        x_str = "DATA";
        break;
      case SA_POP::ENVIRON :
        x_str = "ENVIRON";
        break;
      case SA_POP::SYSTEM :
        x_str = "SYSTEM";
        break;
      default :
        x_str = "UNKNOWN";
        break;
    }
    if (!(o << x_str))
      throw "to_string(float) error writing to ostringstream";
    return o.str();
  };

  inline SANet::CondKind to_kind(std::string x)
  {
    if (x == "DATA")
      return SA_POP::DATA;
    else if (x == "ENVIRON")
      return SA_POP::ENVIRON;
    else if (x == "SYSTEM")
      return SA_POP::SYSTEM;
    throw "to_kind() error unknown condition kind";
  };

};  /* SANet namespace */

#endif /* SANET_STANDALONE not defined */


#if defined (SANET_STANDALONE)
namespace SANet {

  /// Type of a node id (tasks and conditions).
  /// (must be > 0 and unique across all tasks *and* conditions).
  typedef int NodeID;

  /// Type of a condition id.
  /// (must be > 0 and unique across all tasks *and* conditions).
  typedef NodeID CondID;

  /// Type of a condition value.
  typedef bool CondValue;

  /// Type of a condition kind/type.
  enum CondKind {ENVIRON, SYSTEM, DATA};

  /// Type of a condition.
  struct Condition {
    CondID id;
    CondValue value;
    CondKind kind;
    bool operator== (const Condition &s) const { return this->id == s.id; };
    bool operator!= (const Condition &s) const { return !(*this == s); };
    bool operator< (const Condition &s) const { return this->id < s.id; };
  };

  /// Type of a task ID.
  /// (must be > 0 and unique across all tasks *and* conditions).
  typedef NodeID TaskID;

  /// NULL task ID (for unknown/uninitialized tasks).
  const TaskID NULL_TASK_ID = 0;

  /// NULL condition ID (for unknown/uninitialized conditions).
  const CondID NULL_COND_ID = 0;

  /// Type of a port id.
  typedef std::string PortID;

  /// Type of an expected utility calculation (basetype for others).
  /// (N.B. this must be a double or float to handle [0,1] range probabilities
  /// and multiplication factors).
  typedef double EUCalc;
          
  /// Type of a condition utility.
  typedef EUCalc Utility;

  /// Type of a probability.
  typedef EUCalc Probability;

  /// Type of a (precondition or effect) link weight.
  typedef EUCalc LinkWeight;

  /// Type of a task cost.
  typedef EUCalc TaskCost;

  /// Type of a multiplicative factor (e.g. attenuation factor).
  typedef EUCalc MultFactor;

  /// Type of duration
  typedef int TimeValue;

  /// NULL time (for unknown or unconstrained times).
  #define NULL_TIME -1

  /// Type of a precondition link.
  typedef std::pair<CondID, TaskID> PrecondLink;

  /// Type of an effect link.
  typedef std::pair<TaskID, CondID> EffectLink;

  /// Type of a pair of ports for a link.
  typedef std::pair<PortID, PortID> LinkPorts;

  /// Type of a list of tasks.
  typedef std::list<TaskID> TaskList;

  /// Type of a set of goal conditions with associated utilities.
  typedef std::map<CondID, Utility> GoalMap;

  /// Type of a set of tasks with associated expected utilities.
  typedef std::map<TaskID, Utility> TaskEUMap;

  /// Type of a set of conditions (condition & value).
  typedef std::set<Condition> CondSet;

  /// Type of a set of task ids.
  typedef std::set<TaskID> TaskSet;

  inline std::string to_string(int x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(int) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(long x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(long) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(unsigned long x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(unsigned long) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(double x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(double) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(float x)
  {
    std::ostringstream o;
    if (!(o << x))
      throw "to_string(float) error writing to ostringstream";
    return o.str();
  };

  inline std::string to_string(CondKind x)
  {
    std::ostringstream o;
    std::string x_str = "";

    switch (x) {
      case SANet::DATA :
        x_str = "DATA";
        break;
      case SANet::ENVIRON :
        x_str = "ENVIRON";
        break;
      case SANet::SYSTEM :
        x_str = "SYSTEM";
        break;
      default :
        x_str = "UNKNOWN";
        break;
    }
    if (!(o << x_str))
      throw "to_string(float) error writing to ostringstream";
    return o.str();
  };

  inline SANet::CondKind to_kind(std::string x)
  {
    if (x == "DATA")
      return SANet::DATA;
    else if (x == "ENVIRON")
      return SANet::ENVIRON;
    else if (x == "SYSTEM")
      return SANet::SYSTEM;
    throw "to_kind() error unknown condition kind";
  };
};  /* SANet namespace */
#endif /* SANET_STANDALONE */

#endif /* SANET_TYPES_H_ */