Soar Kernel
9.3.2 08-06-12
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
src
decision_manipulation.cpp
Go to the documentation of this file.
1
#include <portability.h>
2
3
/*************************************************************************
4
* PLEASE SEE THE FILE "license.txt" (INCLUDED WITH THIS SOFTWARE PACKAGE)
5
* FOR LICENSE AND COPYRIGHT INFORMATION.
6
*************************************************************************/
7
8
/*************************************************************************
9
*
10
* file: decision_manipulation.cpp
11
*
12
* =======================================================================
13
* Description : Predict/Select functionality
14
* =======================================================================
15
*/
16
17
#include "
decision_manipulation.h
"
18
19
#include "
agent.h
"
20
#include "
soar_rand.h
"
21
22
#include "
decide.h
"
23
#include "misc.h"
24
25
/***************************************************************************
26
* Function : select_init
27
**************************************************************************/
28
void
select_init
(
agent
*my_agent )
29
{
30
my_agent->
select
->
select_enabled
=
false
;
31
my_agent->
select
->
select_operator
.clear();
32
}
33
34
/***************************************************************************
35
* Function : select_next_operator
36
**************************************************************************/
37
void
select_next_operator
(
agent
*my_agent,
const
char
*operator_id )
38
{
39
select_init
( my_agent );
40
std::string& op = my_agent->
select
->
select_operator
;
41
42
my_agent->
select
->
select_enabled
=
true
;
43
op.assign(operator_id);
44
45
assert( !op.empty() );
46
47
// lazy users may use a lower-case letter
48
std::string::iterator iter = op.begin();
49
*iter =
static_cast<
char
>
( toupper( *iter ) );
50
}
51
52
/***************************************************************************
53
* Function : select_get_operator
54
**************************************************************************/
55
const
char
*
select_get_operator
(
agent
*my_agent )
56
{
57
if
( !my_agent->
select
->
select_enabled
)
58
return
NULL;
59
60
return
my_agent->
select
->
select_operator
.c_str();
61
}
62
63
/***************************************************************************
64
* Function : select_force
65
**************************************************************************/
66
preference
*
select_force
(
agent
*my_agent,
preference
*candidates,
bool
reinit )
67
{
68
preference
*return_val = NULL;
69
preference
*cand = candidates;
70
std::string temp;
71
72
if
( my_agent->
select
->
select_enabled
)
73
{
74
// go through the list till we find a match or done
75
while
( cand && !return_val )
76
{
77
if
( cand->
value
->common.symbol_type ==
IDENTIFIER_SYMBOL_TYPE
)
78
{
79
// clear comparison string
80
temp =
""
;
81
82
// get first letter of comparison string
83
temp += cand->
value
->
id
.
name_letter
;
84
85
// get number of comparison string
86
std::string temp2;
87
to_string( cand->
value
->
id
.
name_number
, temp2 );
88
temp += temp2;
89
90
if
( !my_agent->
select
->
select_operator
.compare( temp ) )
91
return_val = cand;
92
}
93
94
cand = cand->
next
;
95
}
96
97
if
( return_val && reinit )
98
select_init
( my_agent );
99
}
100
101
return
return_val;
102
}
103
104
/***************************************************************************
105
* Function : predict_init
106
**************************************************************************/
107
void
predict_init
(
agent
*my_agent )
108
{
109
my_agent->
predict_seed
= 0;
110
(*my_agent->
prediction
) =
""
;
111
}
112
113
/***************************************************************************
114
* Function : predict_srand_store_snapshot
115
**************************************************************************/
116
void
predict_srand_store_snapshot
(
agent
*my_agent )
117
{
118
uint32_t
storage_val = 0;
119
120
while
( !storage_val )
121
storage_val =
SoarRandInt
();
122
123
my_agent->
predict_seed
= storage_val;
124
}
125
126
/***************************************************************************
127
* Function : predict_srand_restore_snapshot
128
**************************************************************************/
129
void
predict_srand_restore_snapshot
(
agent
*my_agent,
bool
clear_snapshot )
130
{
131
if
( my_agent->
predict_seed
)
132
SoarSeedRNG
( my_agent->
predict_seed
);
133
134
if
( clear_snapshot )
135
predict_init
( my_agent );
136
}
137
138
/***************************************************************************
139
* Function : predict_set
140
**************************************************************************/
141
void
predict_set
(
agent
*my_agent,
const
char
*
prediction
)
142
{
143
(*my_agent->
prediction
) = prediction;
144
}
145
146
/***************************************************************************
147
* Function : predict_get
148
**************************************************************************/
149
const
char
*
predict_get
(
agent
*my_agent )
150
{
151
predict_srand_store_snapshot
( my_agent );
152
do_decision_phase
( my_agent,
true
);
153
154
return
my_agent->
prediction
->c_str();
155
}
Generated on Mon Aug 6 2012 17:21:01 for Soar Kernel by
1.8.1.2