Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Seminar-HFO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
Seminar-HFO
Commits
ab59293b
You need to sign in or sign up before continuing.
Commit
ab59293b
authored
Jun 03, 2015
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added infrastructure for choosing between the high/low level feature set.
parent
8c1fef0d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
25 deletions
+88
-25
example/hfo_example_agent.cpp
example/hfo_example_agent.cpp
+4
-3
example/hfo_example_agent.py
example/hfo_example_agent.py
+4
-3
hfo/hfo.py
hfo/hfo.py
+13
-3
src/HFO.cpp
src/HFO.cpp
+8
-3
src/HFO.hpp
src/HFO.hpp
+11
-2
src/agent.cpp
src/agent.cpp
+37
-11
src/agent.h
src/agent.h
+5
-0
src/highlevel_feature_extractor.h
src/highlevel_feature_extractor.h
+6
-0
No files found.
example/hfo_example_agent.cpp
View file @
ab59293b
...
@@ -10,8 +10,9 @@ using namespace std;
...
@@ -10,8 +10,9 @@ using namespace std;
int
main
()
{
int
main
()
{
// Create the HFO environment
// Create the HFO environment
HFOEnvironment
hfo
;
HFOEnvironment
hfo
;
// Connect the agent's server
// Connect the agent's server on the given port with the given
hfo
.
connectToAgentServer
(
6000
);
// feature set. See possible feature sets in src/HFO.hpp.
hfo
.
connectToAgentServer
(
6000
,
LOW_LEVEL_FEATURE_SET
);
// Play 5 episodes
// Play 5 episodes
for
(
int
episode
=
0
;
episode
<
5
;
episode
++
)
{
for
(
int
episode
=
0
;
episode
<
5
;
episode
++
)
{
hfo_status_t
status
=
IN_GAME
;
hfo_status_t
status
=
IN_GAME
;
...
@@ -19,7 +20,7 @@ int main() {
...
@@ -19,7 +20,7 @@ int main() {
// Grab the vector of state features for the current state
// Grab the vector of state features for the current state
const
std
::
vector
<
float
>&
feature_vec
=
hfo
.
getState
();
const
std
::
vector
<
float
>&
feature_vec
=
hfo
.
getState
();
// Create a dash action
// Create a dash action
Action
a
=
{
DASH
,
10
0.
,
0.
};
Action
a
=
{
DASH
,
0.
,
0.
};
// Perform the dash and recieve the current game status
// Perform the dash and recieve the current game status
status
=
hfo
.
act
(
a
);
status
=
hfo
.
act
(
a
);
}
}
...
...
example/hfo_example_agent.py
View file @
ab59293b
...
@@ -12,8 +12,9 @@ if __name__ == '__main__':
...
@@ -12,8 +12,9 @@ if __name__ == '__main__':
exit
()
exit
()
# Create the HFO Environment
# Create the HFO Environment
hfo
=
hfo
.
HFOEnvironment
()
hfo
=
hfo
.
HFOEnvironment
()
# Connect to the agent server
# Connect to the agent server on port 6000 with the specified
hfo
.
connectToAgentServer
()
# feature set. See feature sets in hfo.py/hfo.hpp.
hfo
.
connectToAgentServer
(
6000
,
HFO_Features
.
HIGH_LEVEL_FEATURE_SET
)
# Play 5 episodes
# Play 5 episodes
for
episode
in
xrange
(
5
):
for
episode
in
xrange
(
5
):
status
=
HFO_Status
.
IN_GAME
status
=
HFO_Status
.
IN_GAME
...
@@ -21,7 +22,7 @@ if __name__ == '__main__':
...
@@ -21,7 +22,7 @@ if __name__ == '__main__':
# Grab the state features from the environment
# Grab the state features from the environment
features
=
hfo
.
getState
()
features
=
hfo
.
getState
()
# Take an action and get the current game status
# Take an action and get the current game status
status
=
hfo
.
act
((
HFO_Actions
.
DASH
,
10
0
,
0
))
status
=
hfo
.
act
((
HFO_Actions
.
DASH
,
0
,
0
))
print
'Episode'
,
episode
,
'ended with'
,
print
'Episode'
,
episode
,
'ended with'
,
# Check what the outcome of the episode was
# Check what the outcome of the episode was
if
status
==
HFO_Status
.
GOAL
:
if
status
==
HFO_Status
.
GOAL
:
...
...
hfo/hfo.py
View file @
ab59293b
import
socket
,
struct
,
thread
,
time
import
socket
,
struct
,
thread
,
time
class
HFO_Features
:
''' An enum of the possible HFO feature sets. For descriptions see
https://github.com/mhauskn/HFO/blob/master/doc/manual.pdf
'''
LOW_LEVEL_FEATURE_SET
,
HIGH_LEVEL_FEATURE_SET
=
range
(
2
)
class
HFO_Actions
:
class
HFO_Actions
:
''' An enum of the possible HFO actions
''' An enum of the possible HFO actions
...
@@ -31,7 +38,8 @@ class HFOEnvironment(object):
...
@@ -31,7 +38,8 @@ class HFOEnvironment(object):
self
.
numFeatures
=
None
# Given by the server in handshake
self
.
numFeatures
=
None
# Given by the server in handshake
self
.
features
=
None
# The state features
self
.
features
=
None
# The state features
def
connectToAgentServer
(
self
,
server_port
=
6000
):
def
connectToAgentServer
(
self
,
server_port
=
6000
,
feature_set
=
HFO_Features
.
HIGH_LEVEL_FEATURE_SET
):
'''Connect to the server that controls the agent on the specified port. '''
'''Connect to the server that controls the agent on the specified port. '''
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
print
'[Agent Client] Connecting to Agent Server on port'
,
server_port
print
'[Agent Client] Connecting to Agent Server on port'
,
server_port
...
@@ -44,7 +52,7 @@ class HFOEnvironment(object):
...
@@ -44,7 +52,7 @@ class HFOEnvironment(object):
else
:
else
:
break
break
print
'[Agent Client] Connected'
print
'[Agent Client] Connected'
self
.
handshakeAgentServer
()
self
.
handshakeAgentServer
(
feature_set
)
# Get the initial state
# Get the initial state
state_data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'f'
)
*
self
.
numFeatures
)
state_data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'f'
)
*
self
.
numFeatures
)
if
not
state_data
:
if
not
state_data
:
...
@@ -53,7 +61,7 @@ class HFOEnvironment(object):
...
@@ -53,7 +61,7 @@ class HFOEnvironment(object):
exit
(
1
)
exit
(
1
)
self
.
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
state_data
)
self
.
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
state_data
)
def
handshakeAgentServer
(
self
):
def
handshakeAgentServer
(
self
,
feature_set
):
'''Handshake with the agent's server. '''
'''Handshake with the agent's server. '''
# Recieve float 123.2345
# Recieve float 123.2345
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"f"
))
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"f"
))
...
@@ -61,6 +69,8 @@ class HFOEnvironment(object):
...
@@ -61,6 +69,8 @@ class HFOEnvironment(object):
assert
abs
(
f
-
123.2345
)
<
1e-4
,
"Float handshake failed"
assert
abs
(
f
-
123.2345
)
<
1e-4
,
"Float handshake failed"
# Send float 5432.321
# Send float 5432.321
self
.
socket
.
send
(
struct
.
pack
(
"f"
,
5432.321
))
self
.
socket
.
send
(
struct
.
pack
(
"f"
,
5432.321
))
# Send the feature set request
self
.
socket
.
send
(
struct
.
pack
(
"i"
,
feature_set
))
# Recieve the number of features
# Recieve the number of features
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"i"
))
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"i"
))
self
.
numFeatures
=
struct
.
unpack
(
"i"
,
data
)[
0
]
self
.
numFeatures
=
struct
.
unpack
(
"i"
,
data
)[
0
]
...
...
src/HFO.cpp
View file @
ab59293b
...
@@ -24,7 +24,8 @@ HFOEnvironment::~HFOEnvironment() {
...
@@ -24,7 +24,8 @@ HFOEnvironment::~HFOEnvironment() {
close
(
sockfd
);
close
(
sockfd
);
}
}
void
HFOEnvironment
::
connectToAgentServer
(
int
server_port
)
{
void
HFOEnvironment
::
connectToAgentServer
(
int
server_port
,
feature_set_t
feature_set
)
{
std
::
cout
<<
"[Agent Client] Connecting to Agent Server on port "
std
::
cout
<<
"[Agent Client] Connecting to Agent Server on port "
<<
server_port
<<
std
::
endl
;
<<
server_port
<<
std
::
endl
;
sockfd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
sockfd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
...
@@ -49,7 +50,7 @@ void HFOEnvironment::connectToAgentServer(int server_port) {
...
@@ -49,7 +50,7 @@ void HFOEnvironment::connectToAgentServer(int server_port) {
sleep
(
1
);
sleep
(
1
);
}
}
std
::
cout
<<
"[Agent Client] Connected"
<<
std
::
endl
;
std
::
cout
<<
"[Agent Client] Connected"
<<
std
::
endl
;
handshakeAgentServer
();
handshakeAgentServer
(
feature_set
);
// Get the initial game state
// Get the initial game state
feature_vec
.
resize
(
numFeatures
);
feature_vec
.
resize
(
numFeatures
);
if
(
recv
(
sockfd
,
&
(
feature_vec
.
front
()),
numFeatures
*
sizeof
(
float
),
0
)
<
0
)
{
if
(
recv
(
sockfd
,
&
(
feature_vec
.
front
()),
numFeatures
*
sizeof
(
float
),
0
)
<
0
)
{
...
@@ -57,7 +58,7 @@ void HFOEnvironment::connectToAgentServer(int server_port) {
...
@@ -57,7 +58,7 @@ void HFOEnvironment::connectToAgentServer(int server_port) {
}
}
}
}
void
HFOEnvironment
::
handshakeAgentServer
()
{
void
HFOEnvironment
::
handshakeAgentServer
(
feature_set_t
feature_set
)
{
// Recieve float 123.2345
// Recieve float 123.2345
float
f
;
float
f
;
if
(
recv
(
sockfd
,
&
f
,
sizeof
(
float
),
0
)
<
0
)
{
if
(
recv
(
sockfd
,
&
f
,
sizeof
(
float
),
0
)
<
0
)
{
...
@@ -72,6 +73,10 @@ void HFOEnvironment::handshakeAgentServer() {
...
@@ -72,6 +73,10 @@ void HFOEnvironment::handshakeAgentServer() {
if
(
send
(
sockfd
,
&
f
,
sizeof
(
float
),
0
)
<
0
)
{
if
(
send
(
sockfd
,
&
f
,
sizeof
(
float
),
0
)
<
0
)
{
error
(
"[Agent Client] ERROR sending from socket"
);
error
(
"[Agent Client] ERROR sending from socket"
);
}
}
// Send the feature set request
if
(
send
(
sockfd
,
&
feature_set
,
sizeof
(
int
),
0
)
<
0
)
{
error
(
"[Agent Client] ERROR sending from socket"
);
}
// Recieve the number of features
// Recieve the number of features
if
(
recv
(
sockfd
,
&
numFeatures
,
sizeof
(
int
),
0
)
<
0
)
{
if
(
recv
(
sockfd
,
&
numFeatures
,
sizeof
(
int
),
0
)
<
0
)
{
error
(
"[Agent Client] ERROR recv from socket"
);
error
(
"[Agent Client] ERROR recv from socket"
);
...
...
src/HFO.hpp
View file @
ab59293b
...
@@ -3,6 +3,14 @@
...
@@ -3,6 +3,14 @@
#include <vector>
#include <vector>
// For descriptions of the different feature sets see
// https://github.com/mhauskn/HFO/blob/master/doc/manual.pdf
enum
feature_set_t
{
LOW_LEVEL_FEATURE_SET
,
HIGH_LEVEL_FEATURE_SET
};
// The actions available to the agent
// The actions available to the agent
enum
action_t
enum
action_t
{
{
...
@@ -39,7 +47,8 @@ class HFOEnvironment {
...
@@ -39,7 +47,8 @@ class HFOEnvironment {
~
HFOEnvironment
();
~
HFOEnvironment
();
// Connect to the server that controls the agent on the specified port.
// Connect to the server that controls the agent on the specified port.
void
connectToAgentServer
(
int
server_port
=
6008
);
void
connectToAgentServer
(
int
server_port
=
6000
,
feature_set_t
feature_set
=
HIGH_LEVEL_FEATURE_SET
);
// Get the current state of the domain. Returns a reference to feature_vec.
// Get the current state of the domain. Returns a reference to feature_vec.
const
std
::
vector
<
float
>&
getState
();
const
std
::
vector
<
float
>&
getState
();
...
@@ -54,7 +63,7 @@ class HFOEnvironment {
...
@@ -54,7 +63,7 @@ class HFOEnvironment {
// Handshake with the agent server to ensure data is being correctly
// Handshake with the agent server to ensure data is being correctly
// passed. Also sets the number of features to expect.
// passed. Also sets the number of features to expect.
virtual
void
handshakeAgentServer
();
virtual
void
handshakeAgentServer
(
feature_set_t
feature_set
);
};
};
#endif
#endif
src/agent.cpp
View file @
ab59293b
...
@@ -137,7 +137,10 @@ Agent::Agent()
...
@@ -137,7 +137,10 @@ Agent::Agent()
M_action_generator
(
createActionGenerator
()),
M_action_generator
(
createActionGenerator
()),
lastTrainerMessageTime
(
-
1
),
lastTrainerMessageTime
(
-
1
),
server_port
(
6008
),
server_port
(
6008
),
server_running
(
false
)
server_running
(
false
),
num_teammates
(
-
1
),
num_opponents
(
-
1
),
playing_offense
(
false
)
{
{
boost
::
shared_ptr
<
AudioMemory
>
audio_memory
(
new
AudioMemory
);
boost
::
shared_ptr
<
AudioMemory
>
audio_memory
(
new
AudioMemory
);
...
@@ -198,13 +201,11 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
...
@@ -198,13 +201,11 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
// read additional options
// read additional options
result
&=
Strategy
::
instance
().
init
(
cmd_parser
);
result
&=
Strategy
::
instance
().
init
(
cmd_parser
);
int
numTeammates
,
numOpponents
;
bool
playingOffense
;
rcsc
::
ParamMap
my_params
(
"Additional options"
);
rcsc
::
ParamMap
my_params
(
"Additional options"
);
my_params
.
add
()
my_params
.
add
()
(
"numTeammates"
,
""
,
&
num
T
eammates
)
(
"numTeammates"
,
""
,
&
num
_t
eammates
)
(
"numOpponents"
,
""
,
&
num
O
pponents
)
(
"numOpponents"
,
""
,
&
num
_o
pponents
)
(
"playingOffense"
,
""
,
&
playing
O
ffense
)
(
"playingOffense"
,
""
,
&
playing
_o
ffense
)
(
"serverPort"
,
""
,
&
server_port
);
(
"serverPort"
,
""
,
&
server_port
);
cmd_parser
.
parse
(
my_params
);
cmd_parser
.
parse
(
my_params
);
if
(
cmd_parser
.
count
(
"help"
)
>
0
)
{
if
(
cmd_parser
.
count
(
"help"
)
>
0
)
{
...
@@ -245,11 +246,8 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
...
@@ -245,11 +246,8 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
<<
std
::
endl
;
<<
std
::
endl
;
}
}
assert
(
numTeammates
>=
0
);
assert
(
num_teammates
>=
0
);
assert
(
numOpponents
>=
0
);
assert
(
num_opponents
>=
0
);
feature_extractor
=
new
LowLevelFeatureExtractor
(
numTeammates
,
numOpponents
,
playingOffense
);
return
true
;
return
true
;
}
}
...
@@ -292,6 +290,13 @@ void Agent::clientHandshake() {
...
@@ -292,6 +290,13 @@ void Agent::clientHandshake() {
if
(
abs
(
f
-
5432.321
)
>
1e-4
)
{
if
(
abs
(
f
-
5432.321
)
>
1e-4
)
{
error
(
"[Agent Server] Handshake failed. Improper float recieved."
);
error
(
"[Agent Server] Handshake failed. Improper float recieved."
);
}
}
// Recieve the feature set to use
feature_set_t
feature_set
;
if
(
recv
(
newsockfd
,
&
feature_set
,
sizeof
(
int
),
0
)
<
0
)
{
error
(
"[Agent Server] ERROR recv from socket"
);
}
// Create the corresponding FeatureExtractor
feature_extractor
=
getFeatureExtractor
(
feature_set
);
// Send the number of features
// Send the number of features
int
numFeatures
=
feature_extractor
->
getNumFeatures
();
int
numFeatures
=
feature_extractor
->
getNumFeatures
();
assert
(
numFeatures
>
0
);
assert
(
numFeatures
>
0
);
...
@@ -309,6 +314,27 @@ void Agent::clientHandshake() {
...
@@ -309,6 +314,27 @@ void Agent::clientHandshake() {
std
::
cout
<<
"[Agent Server] Handshake complete"
<<
std
::
endl
;
std
::
cout
<<
"[Agent Server] Handshake complete"
<<
std
::
endl
;
}
}
FeatureExtractor
*
Agent
::
getFeatureExtractor
(
feature_set_t
feature_set_indx
)
{
if
(
feature_extractor
!=
NULL
)
{
delete
feature_extractor
;
}
switch
(
feature_set_indx
)
{
case
LOW_LEVEL_FEATURE_SET
:
return
new
LowLevelFeatureExtractor
(
num_teammates
,
num_opponents
,
playing_offense
);
break
;
case
HIGH_LEVEL_FEATURE_SET
:
return
new
HighLevelFeatureExtractor
(
num_teammates
,
num_opponents
,
playing_offense
);
break
;
default:
std
::
cerr
<<
"[Feature Extractor] ERROR Unrecognized Feature set index: "
<<
feature_set_indx
<<
std
::
endl
;
exit
(
1
);
}
}
hfo_status_t
Agent
::
getGameStatus
()
{
hfo_status_t
Agent
::
getGameStatus
()
{
hfo_status_t
game_status
=
IN_GAME
;
hfo_status_t
game_status
=
IN_GAME
;
if
(
audioSensor
().
trainerMessageTime
().
cycle
()
>
lastTrainerMessageTime
)
{
if
(
audioSensor
().
trainerMessageTime
().
cycle
()
>
lastTrainerMessageTime
)
{
...
...
src/agent.h
View file @
ab59293b
...
@@ -69,12 +69,17 @@ protected:
...
@@ -69,12 +69,17 @@ protected:
// Transmit information to the client and ensure it can recieve.
// Transmit information to the client and ensure it can recieve.
void
clientHandshake
();
void
clientHandshake
();
// Returns the feature extractor corresponding to the feature_set_t
FeatureExtractor
*
getFeatureExtractor
(
feature_set_t
feature_set
);
protected:
protected:
FeatureExtractor
*
feature_extractor
;
FeatureExtractor
*
feature_extractor
;
long
lastTrainerMessageTime
;
// Last time the trainer sent a message
long
lastTrainerMessageTime
;
// Last time the trainer sent a message
int
server_port
;
// Port to start the server on
int
server_port
;
// Port to start the server on
bool
server_running
;
// Is the server running?
bool
server_running
;
// Is the server running?
int
sockfd
,
newsockfd
;
// Server sockets
int
sockfd
,
newsockfd
;
// Server sockets
int
num_teammates
,
num_opponents
;
bool
playing_offense
;
private:
private:
bool
doPreprocess
();
bool
doPreprocess
();
...
...
src/highlevel_feature_extractor.h
View file @
ab59293b
...
@@ -5,6 +5,12 @@
...
@@ -5,6 +5,12 @@
#include "feature_extractor.h"
#include "feature_extractor.h"
#include <vector>
#include <vector>
/**
* This feature extractor creates the high level feature set used by
* Barrett et al.
* (http://www.cs.utexas.edu/~sbarrett/publications/details-THESIS14-Barrett.html)
* pages 159-160.
*/
class
HighLevelFeatureExtractor
:
public
FeatureExtractor
{
class
HighLevelFeatureExtractor
:
public
FeatureExtractor
{
public:
public:
HighLevelFeatureExtractor
(
int
num_teammates
,
int
num_opponents
,
HighLevelFeatureExtractor
(
int
num_teammates
,
int
num_opponents
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment