コード例 #1
0
 def _save(self):
     rootDirectory = \
         self.tableModel.rootDirectory if hasattr(self.tableModel, 
                                                  "rootDirectory") \
             else mmlf.getRWPath()
     graphicFileName = \
         str(QtGui.QFileDialog.getSaveFileName(self,
                                               "Select a file for the stored graphic",
                                               rootDirectory,   
                                               "Plots (*.pdf)"))
     self.fig.savefig(str(graphicFileName), dpi=400)
コード例 #2
0
    def __init__(self, basePath=mmlf.getRWPath()):
        self.basePath = basePath

        # dictionary of strings used to refer to a path (as the keys), and the
        # strings containing the absolute path for these paths (as the values).
        self.pathDict = {}

        self.timeString = None
        self.setBasePath(basePath)  # set path to default location

        # Some root directories are added to the base user directory
        self.createPath(["config"], refName="rwconfig", force=True)

        # Set ro_area
        head = os.path.split(os.path.abspath(__file__))[0]
        head = os.path.split(head)[0]
        self.addAbsolutePath(head, "ro_area")
        head = os.path.split(head)[0]
        self.addAbsolutePath(head + os.sep + "config", "roconfig")
コード例 #3
0
ファイル: world_config_editor.py プロジェクト: mekruthi/mmlf
    def loadConfig(self):
        """ Opens dialog to load an MMLF world from yaml file.
        
        Returns whether a file was selected and loaded.
        """
        # Read world configuration from yaml configuration file
        worldConfFile = \
            str(QtGui.QFileDialog.getOpenFileName(self.parent,
                                                  "Select a MMLF world config file",
                                                  mmlf.getRWPath() + os.sep + "config",
                                                  "MMLF world config files (*.yaml)"))
        if worldConfFile == "": return False  # No file was selected
        worldConfig = yaml.load(open(worldConfFile, 'r'))

        # Add missing entries for the monitor to worldConfig
        for key in Monitor.DEFAULT_CONFIG_DICT.keys():
            if key not in worldConfig["monitor"]:
                worldConfig["monitor"][key] = deepcopy(
                    Monitor.DEFAULT_CONFIG_DICT[key])

        self._initFromWorldConfigObject(worldConfig)
        return True
コード例 #4
0
ファイル: world_config_editor.py プロジェクト: mekruthi/mmlf
    def storeConfig(self):
        """ Opens dialog to store an MMLF world to a yaml file.
        
        Returns whether a file was selected and stroed.
        """
        worldConfigObject = self.createWorldConfigObject()

        # Store world configuration to yaml configuration file
        worldConfDirectory = mmlf.getRWPath() + os.sep + "config" \
                                + os.sep + worldConfigObject["worldPackage"]
        worldConfFile = \
            str(QtGui.QFileDialog.getSaveFileName(self.parent,
                                                  "Select a MMLF world config file",
                                                  worldConfDirectory,
                                                  "MMLF world config files (*.yaml)"))

        if worldConfFile == "": return False  # No file was selected

        yaml.dump(dict(worldConfigObject),
                  open(worldConfFile, 'w'),
                  default_flow_style=False)

        return True
コード例 #5
0
class BaseUserDirectory(object):
    """ Represents a user's base-directory (typically $HOME/.mmlf)
    
    In this directory, the user can define worlds, YAML configuration files, 
    and the interaction server logs information while running a world.
    """
    def __init__(self, basePath=mmlf.getRWPath()):
        self.basePath = basePath

        # dictionary of strings used to refer to a path (as the keys), and the
        # strings containing the absolute path for these paths (as the values).
        self.pathDict = {}

        self.timeString = None
        self.setBasePath(basePath)  # set path to default location

        # Some root directories are added to the base user directory
        self.createPath(["config"], refName="rwconfig", force=True)

        # Set ro_area
        head = os.path.split(os.path.abspath(__file__))[0]
        head = os.path.split(head)[0]
        self.addAbsolutePath(head, "ro_area")
        head = os.path.split(head)[0]
        self.addAbsolutePath(head + os.sep + "config", "roconfig")

    def setBasePath(self, absolutePath=None):
        """
        Set (and create if necessary) the base user-directory path.  If a path is specified
        (as an absolute path string), then it is used.  Otherwise, the default path is
        used.
        
        If for some reason this fails, then a writeable temporary directory is chosen.
        """
        # if absolute path is specified, then use it.
        if absolutePath != None:
            try:
                self.createPath(
                    [], refName='basepath'
                )  # try creating the directory specified by self.basePath
                self.basePath = absolutePath
                return  # if successful, then exit the method
            except Exception, e:
                warnings.warn(
                    "Could not create user directory for given absolute path %s. \n Reason: %s\n"
                    % (absolutePath, e))

        self.basePath = os.path.abspath(mmlf.getRWPath())

        try:
            self.createPath(
                [], refName='basepath'
            )  # try creating the directory specified by self.basePath
        except Exception, e:
            # if creating the self.basePath directory fails, then we need
            # to choose a directory in the $TEMP directory which is writeable.
            self.basePath = tempfile.mkdtemp()
            self.pathDict['basepath'] = self.basePath  # add to path dictionary

            warnings.warn(
                "Could not create default user directory. Using %s instead.\n Reason: %s\n"
                % (self.basePath, e))
コード例 #6
0
ファイル: maze2d_environment.py プロジェクト: mekruthi/mmlf
    def __init__(self, useGUI, *args, **kwargs):

        self.environmentInfo = EnvironmentInfo(versionNumber="0.3",
                                               environmentName="Maze2D",
                                               discreteActionSpace=True,
                                               episodic=True,
                                               continuousStateSpace=False,
                                               continuousActionSpace=False,
                                               stochastic=False)

        super(Maze2dEnvironment, self).__init__(useGUI=useGUI, *args, **kwargs)

        # Reading string which describes the structure of the maze
        mazeDescriptionString = open(mmlf.getRWPath() + os.sep + "config" +
                                     os.sep + "maze2d" + os.sep +
                                     self.configDict['MAZE']).read()
        # Remove comment lines and superfluous whitespace
        lines = map(lambda line: line.strip(),
                    mazeDescriptionString.split("\n"))
        lines = filter(lambda line: not line.startswith("#"), lines)
        mazeDescriptionString = "\n".join(lines)

        #The maze object is created from the description
        self.maze = Maze.createMazeFromString(mazeDescriptionString)

        #The state space of the Maze2d Simulation
        oldStyleStateSpace = {
            "column": ("discrete", range(self.maze.getColumns())),
            "row": ("discrete", range(self.maze.getRows()))
        }

        self.stateSpace = StateSpace()
        self.stateSpace.addOldStyleSpace(oldStyleStateSpace, limitType="soft")

        #The action space of the Maze2d Simulation
        oldStyleActionSpace = {
            "action": ("discrete", ["left", "right", "up", "down"])
        }

        self.actionSpace = ActionSpace()
        self.actionSpace.addOldStyleSpace(oldStyleActionSpace,
                                          limitType="soft")

        #The current state of the simulation
        self.initialState = {
            "row": self.maze.getStartPosition()[0],
            "column": self.maze.getStartPosition()[1]
        }
        #The current state is initially set to the initial state
        self.currentState = deepcopy(self.initialState)

        if useGUI:
            from mmlf.gui.viewers import VIEWERS
            from mmlf.gui.viewers.trajectory_viewer import TrajectoryViewer
            from mmlf.worlds.maze2d.environments.maze2d_viewer import Maze2DDetailedViewer
            from mmlf.worlds.maze2d.environments.maze2d_function_viewer import Maze2DFunctionViewer

            # Create customized trajectory viewer
            class Maze2dTrajectoryViewer(TrajectoryViewer):
                def __init__(self, stateSpace, plotStateSpaceStructure):
                    super(Maze2dTrajectoryViewer, self).__init__(stateSpace)
                    plotStateSpaceStructure(self.axisTrajectory)


            VIEWERS.addViewer(lambda : \
                                Maze2dTrajectoryViewer(self.stateSpace,
                                                       lambda ax : self.plotStateSpaceStructure(ax)),
                              'Maze2dTrajectoryViewer')

            # Add viewers for the maze world
            VIEWERS.addViewer(
                lambda: Maze2DDetailedViewer(self.maze, self.stateSpace,
                                             ["left", "right", "up", "down"]),
                'Maze2DDetailedViewer')
            VIEWERS.addViewer(
                lambda: Maze2DFunctionViewer(self.maze, self.stateSpace),
                'Maze2DFunctionViewer')