Пример #1
0
def transfer2JavaDblAry(gateway, pyArray, size):
    dblAry = gateway.new_array(gateway.jvm.double, size)
    i = 0
    for x in pyArray:
        dblAry[i] = float(x)
        i = i + 1
    return dblAry
Пример #2
0
def transfer2JavaStringAry(gateway, pyArray):

    strAry = gateway.new_array(gateway.jvm.String, len(pyArray))
    i = 0
    for x in pyArray:
        strAry[i] = str(x)
        i = i + 1
    return strAry
Пример #3
0
    def _step(self, action):

        assert self.action_space.contains(
            action), "%r (%s) invalid" % (action, type(action))

        # print(action)
        #         actionMapped = refer(action)
        #         print(actionMapped)
        #actionPyAry = np.asarray(actionMapped,dtype = np.float64)
        actionPyAry = np.asarray(action, dtype=np.float64)

        # print(actionPyAry, 'len = ', actionPyAry.size)

        # np array size = number of elements in the array
        actionJavaAry = gateway.new_array(gateway.jvm.double, actionPyAry.size)

        if (actionPyAry.size == 1):
            actionJavaAry[0] = float(action)
        else:
            i = 0
            for x in actionPyAry:
                actionJavaAry[i] = x
                i = i + 1

        ipss_app.nextStepDynSim(self.step_time, actionJavaAry,
                                self.action_type)

        # retrieve the state from InterPSS simulation service

        # observations is a Java_Collections array
        observations = ipss_app.getEnvironmentObversations()

        # convert it from Java_collections array to native Python array
        self.state = transfer2DJavaArray2NumpyArray(observations)

        #check the states to see whether it go beyond the limits
        done = ipss_app.isSimulationDone()

        if not done:
            reward = ipss_app.getReward()

        elif self.steps_beyond_done is None:
            self.steps_beyond_done = 0
            reward = ipss_app.getReward(
            )  # even it is done, ipss_app would calculate and return a corresponding reward
        else:
            if self.steps_beyond_done == 0:
                logger.warning(
                    "You are calling 'step()' even though this environment has already returned done = True. You should always call 'reset()' once you receive 'done = True' -- any further steps are undefined behavior."
                )
            self.steps_beyond_done += 1

            reward = 0.0

        return np.array(self.state).ravel(), reward, done, {}