24 #include "ArgumentParser.h"
25 #include "ClientConnection.h"
26 #include "ClientPool.h"
27 #include "MissionInitSpec.h"
28 #include "MissionRecord.h"
29 #include "MissionSpec.h"
30 #include "StringServer.h"
31 #include "VideoServer.h"
32 #include "WorldState.h"
34 #include "TCPClient.h"
37 #include <boost/thread.hpp>
50 MISSION_BAD_ROLE_REQUEST,
51 MISSION_BAD_VIDEO_REQUEST,
52 MISSION_ALREADY_RUNNING,
53 MISSION_INSUFFICIENT_CLIENTS_AVAILABLE,
54 MISSION_TRANSMISSION_ERROR,
55 MISSION_SERVER_WARMING_UP,
56 MISSION_SERVER_NOT_FOUND,
57 MISSION_NO_COMMAND_PORT,
58 MISSION_BAD_INSTALLATION,
59 MISSION_CAN_NOT_KILL_BUSY_CLIENT,
60 MISSION_CAN_NOT_KILL_IRREPLACEABLE_CLIENT
63 MissionException(
const std::string& message, MissionErrorCode code) : message(message), code(code) {}
65 MissionErrorCode getMissionErrorCode()
const {
return this->code; }
66 std::string getMessage()
const {
return this->message; }
67 const char* what()
const throw() {
return this->message.c_str(); }
71 MissionErrorCode code;
166 friend std::ostream& operator<<(std::ostream& os,
const AgentHost& ah);
169 static void testSchemasCompatible();
170 static std::string extractVersionNumber(std::string name);
172 void initializeOurServers(
const MissionSpec& mission,
const MissionRecordSpec& mission_record,
int role, std::string unique_experiment_id);
173 std::string generateMissionInit();
176 void findClient(
const ClientPool& client_pool);
177 bool findServer(
const ClientPool& client_pool);
179 void listenForMissionControlMessages(
int port );
180 boost::shared_ptr<VideoServer> listenForVideo(boost::shared_ptr<VideoServer> video_server,
int port,
short width,
short height,
short channels,
TimestampedVideoFrame::FrameType frametype);
181 void listenForRewards(
int port );
182 void listenForObservations(
int port );
189 void openCommandsConnection();
193 void closeRecording();
197 boost::asio::io_service io_service;
198 boost::shared_ptr<StringServer> mission_control_server;
199 boost::shared_ptr<VideoServer> video_server;
200 boost::shared_ptr<VideoServer> depth_server;
201 boost::shared_ptr<VideoServer> luminance_server;
202 boost::shared_ptr<VideoServer> colourmap_server;
203 boost::shared_ptr<StringServer> rewards_server;
204 boost::shared_ptr<StringServer> observations_server;
205 boost::optional<boost::asio::io_service::work> work;
206 std::vector<boost::shared_ptr<boost::thread>> background_threads;
208 boost::shared_ptr<ClientConnection> commands_connection;
209 std::ofstream commands_stream;
216 mutable boost::mutex world_state_mutex;
218 boost::shared_ptr<MissionInitSpec> current_mission_init;
219 boost::shared_ptr<MissionRecord> current_mission_record;
An agent host mediates between the researcher's code (the agent) and the Mod (the target environment)...
Definition: AgentHost.h:76
void startMission(const MissionSpec &mission, const MissionRecordSpec &mission_record)
Starts a mission running, in the simple case where there is only one agent running on the local machi...
RewardsPolicy
Specifies what to do when there are more rewards being received than can be processed.
Definition: AgentHost.h:87
@ LATEST_REWARD_ONLY
Discard all but the most recent reward.
Definition: AgentHost.h:88
@ SUM_REWARDS
Add up all the rewards received. This is the default.
Definition: AgentHost.h:89
@ KEEP_ALL_REWARDS
Attempt to store all the rewards.
Definition: AgentHost.h:90
void setObservationsPolicy(ObservationsPolicy observationsPolicy)
Specifies how you want to deal with multiple observations.
boost::shared_ptr< MissionInitSpec > getMissionInit()
Returns a pointer to the current MissionInitSpec, to allow retrieval of the ports being used.
void sendCommand(std::string command)
Sends a command to the game client.
bool killClient(const ClientInfo &client)
Attempts to remotely shut down a Minecraft client - useful in cases when Minecraft has become old and...
void setRewardsPolicy(RewardsPolicy rewardsPolicy)
Specifies how you want to deal with multiple rewards.
void sendCommand(std::string command, std::string key)
Sends a turn-based command to the game client.
std::string getRecordingTemporaryDirectory() const
Gets the temporary directory being used for the mission record, if recording is taking place.
void setDebugOutput(bool debug)
Switches on/off debug print statements. DEPRECATED - use Logger::setLogging instead.
WorldState peekWorldState() const
Gets the latest world state received from the game.
VideoPolicy
Specifies what to do when there are more video frames being received than can be processed.
Definition: AgentHost.h:81
@ KEEP_ALL_FRAMES
Attempt to store all of the frames.
Definition: AgentHost.h:83
@ LATEST_FRAME_ONLY
Discard all but the most recent frame. This is the default.
Definition: AgentHost.h:82
ObservationsPolicy
Specifies what to do when there are more observations being received than can be processed.
Definition: AgentHost.h:94
@ KEEP_ALL_OBSERVATIONS
Attempt to store all the observations.
Definition: AgentHost.h:96
@ LATEST_OBSERVATION_ONLY
Discard all but the most recent observation. This is the default.
Definition: AgentHost.h:95
WorldState getWorldState()
Gets the latest world state received from the game and resets it to empty.
void startMission(const MissionSpec &mission, const ClientPool &client_pool, const MissionRecordSpec &mission_record, int role, std::string unique_experiment_id)
Starts a mission running.
AgentHost()
Creates an agent host with default settings.
void setVideoPolicy(VideoPolicy videoPolicy)
Specifies how you want to deal with multiple video frames.
A general purpose command-line argument parser.
Definition: ArgumentParser.h:34
Definition: AgentHost.h:46
Specifies a mission to be run.
Definition: MissionSpec.h:37
A map of int:double storing a value on each dimension, with an attached timestamp saying when it was ...
Definition: TimestampedReward.h:35
Structure containing information about a simulation client's address and port.
Definition: ClientInfo.h:34
A pool of expected network locations of Mod clients.
Definition: ClientPool.h:34
Specifies the type of data that should be recorded from the mission.
Definition: MissionRecordSpec.h:42
A string with an attached timestamp saying when it was collected.
Definition: TimestampedString.h:36
An image with an attached timestamp saying when it was collected.
Definition: TimestampedVideoFrame.h:36
FrameType
Definition: TimestampedVideoFrame.h:42
Represents the state of the game world at a moment in time.
Definition: WorldState.h:35