当前位置: 首页>>代码示例>>Python>>正文


Python Agent.run方法代码示例

本文整理汇总了Python中agent.Agent.run方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.run方法的具体用法?Python Agent.run怎么用?Python Agent.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在agent.Agent的用法示例。


在下文中一共展示了Agent.run方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HighPower_SomeState2

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import run [as 别名]
class HighPower_SomeState2(HighPower):
  def setUp(self):
    self.agent = Agent()
    self.agent.items = [1, 1]

  def test_02(self):
    p = (1, 0, 1, 0, 20)
    self.assertTrue("ADVANCE_" in self.agent.run(*p))

  def test_0(self):
    p = (1, 0, 1, 1, 20)
    self.assertTrue("ADVANCE_" in self.agent.run(*p))
开发者ID:andrewdyates,项目名称:CSE-630,代码行数:14,代码来源:test.py

示例2: main

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import run [as 别名]
def main():
    """ Main entry point for executable. """

    a = Agent()
    Agent.DEBUG = True

    cmd_handler = PayloadCommandHandler()

    # Register some callbacks
    a.service_handler["Payload Command"] = cmd_handler.dispatch;
    a.service_handler["Telemetry Packet"] = Agent.print_it;

    print("Binding UDP sockets")
    a.bind_udp_sockets()

    print("Waiting for bus")
    a.run()
开发者ID:SpaceVR-O1,项目名称:OverviewOne,代码行数:19,代码来源:run_agent.py

示例3: main

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import run [as 别名]
def main():

    args = parse_options()

    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

    store = ObjectStore()
    backend = MockBackend(store, in_out_iface=args.in_out_iface,
                                 in_out_stag=None if args.in_out_stag is None else int(args.in_out_stag))
    agent = Agent(args.controller, int(args.datapath_id), store, backend)
    store.set_agent(agent)
    backend.set_agent(agent)

    try:
        agent.run()
    except KeyboardInterrupt:
        logging.info("Ctrl-c received! Shutting down connection and exiting...")
        agent.stop()
        backend.stop()
开发者ID:gcgirish-radisys,项目名称:voltha,代码行数:21,代码来源:main.py

示例4: HighPower

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import run [as 别名]
class HighPower(unittest.TestCase):
  def setUp(self):
    self.agent = Agent()

  def test_1(self):
    p = (1, 1, 1, 1, 20)
    self.assertTrue("ADVANCE_" in self.agent.run(*p))

  def test_0(self):
    p = (1, 0, 1, 1, 20)
    self.assertEqual(self.agent.run(*p), "ADVANCE_B")

  def test_02(self):
    p = (1, 0, 1, 0, 20)
    self.assertEqual(self.agent.run(*p), "PICKUP_A")

  def test_01(self):
    p = (0, 0, 1, 0, 20)
    self.assertEqual(self.agent.run(*p), "ADVANCE_A")

  def test_all_0(self):
    p = (0, 0, 0, 0, 20)
    self.assertEqual(self.agent.run(*p), "ADVANCE_A")

  def test_all_n1(self):
    p = (-1, -1, -1, -1, 20)
    self.assertEqual(self.agent.run(*p), "STOP")

  def test_n1_1(self):
    p = (0, -1, -1, -1, 20)
    self.assertEqual(self.agent.run(*p), "STOP")

  def test_n1_1(self):
    p = (0, -1, -1, -1, 20)
    self.assertEqual(self.agent.run(*p), "STOP")

  def test_n1_2(self):
    p = (0, -1, 0, -1, 20)
    self.assertEqual(self.agent.run(*p), "STOP")

  def test_n1_3(self):
    p = (0, -1, 0, 0, 20)
    self.assertEqual(self.agent.run(*p), "ADVANCE_B")

  def test_n1_4(self):
    p = (0, 0, 0, -1, 20)
    self.assertEqual(self.agent.run(*p), "ADVANCE_A")

  def test_n1_4(self):
    p = (0, 0, 0, -1, 20)
    self.assertEqual(self.agent.run(*p), "ADVANCE_A")
开发者ID:andrewdyates,项目名称:CSE-630,代码行数:53,代码来源:test.py

示例5: __init__

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import run [as 别名]
class BbbSoftware:

    # Timeout after waiting for any network event
    MAIN_LOOP_TIMEOUT = 1.0 # seconds

    def __init__(self):
        self.agent = None
        self.payload_cmds = None

        # Event object to wake the flight control loop
        self.event = threading.Event()

        # Initialize components of state machine
        self.hardware = Hardware()

        # Initialize state
        self.state = State.INITIAL

        # Initialize stats
        self.stats = Stats()

    def on_telemetry(self, packet):
        # Decode as telemetry packet
        tp = TelemetryPacket(packet)
        tp.deserialize()
        # Update newest data
        self.hardware.telemetry = tp
        # Wake the main control thread
        self.event.set()

    def thread_agent(self):
        """
        This is the entry point for the thread that handles
        all communication with the Supernova bus.
        It communicates back to the main ConnOps loop via
        multithreaded Event objects.
        """
        while True:
            try:
                # Set up the command handlers
                self.agent = Agent()
                self.agent.service_handler["Telemetry Packet"] = self.on_telemetry

                # Run
                self.agent.bind_udp_sockets()
                self.agent.run() # should never exit

            except Exception as ex:
                # NOTE: It is an error to ever reach this line.
                # Catch and swallow all exceptions.
                1 + 1

            # NOTE: It is an error to ever reach this line.
            self.agent_errors = self.agent_errors + 1

    def main(self):
        # Launch the thread that communicates with the Supernova bus.
        agent_thread = threading.Thread(target=self.thread_agent)
        agent_thread.daemon = True
        agent_thread.start()

        # Run the flight state machine program
        while True:
            self.event.wait(BbbSoftware.MAIN_LOOP_TIMEOUT)
            self.state = Transitions.next(self.state)
开发者ID:SpaceVR-O1,项目名称:OverviewOne,代码行数:67,代码来源:bbb_main.py

示例6: __init__

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import run [as 别名]
class Tk1Main:

    DEBUG = False

    KERNEL_MOD_PATH = "../UVCStill/uvcstill.ko"

    def __init__(self):
        """ Constructor """

        self.cmds = self.create_payload_cmd_handler()
        self.agent = Agent()
        self.agent.service_handler["Payload Command"] = self.cmds.dispatch

        self.capture_proc = None


    def create_payload_cmd_handler(self):
        """
        Create the payload command handler.

        This establishes the mapping of our command IDs to the
        code that handles them.  Adding a new payload command
        requires linking to it here.
        """
        handler = PayloadCommandHandler()

        handler.handlers.update( {
            PayloadCommandId.ABORT_CAPTURE : self.do_abort_capture,
            PayloadCommandId.CAPTURE_360   : self.do_capture_360,
            PayloadCommandId.CAPTURE_180   : self.do_capture_180,
            PayloadCommandId.CAPTURE_CUSTOM: self.do_capture_custom,
            PayloadCommandId.CAMERA_POWER_ON  : self.do_cameras_on,
            PayloadCommandId.CAMERA_POWER_OFF : self.do_cameras_off,
            PayloadCommandId.RELOAD_KERNEL_MODULE : self.reload_kernel_module,
        } )

        if Tk1Main.DEBUG: PayloadCommandHandler.DEBUG = True

        return handler


    def main(self):
        """
        Start up the Pumpkin Supernova agent and wait for commands.
        """
        
        if Tk1Main.DEBUG: print("Binding UDP sockets")
        self.agent.bind_udp_sockets()
        if Tk1Main.DEBUG: print("Waiting for bus")
        self.agent.run()


    def do_abort_capture(self, packet):
        """
        Immediately terminate any camera captures that are in progress.
        """

        if self.capture_proc and not self.capture_proc.poll():
            if Tk1Main.DEBUG: print("Aborting capture")
            # Send a SIGTERM to capture process
            self.capture_proc.send_signal(signal.SIGTERM)
        else:
            if Tk1Main.DEBUG: print("No capture to abort")



    def do_capture_180(self, packet):
        """
        Capture a 180-degree sequence.
        """

        if (packet.data_len <= 8):
            # Ignore bad packets.
            return

        (num_frames, start_time) = struct.unpack("ll", packet.data)

        self.capture(4, num_frames, start_time)


    def do_capture_360(self, packet):
        """
        Capture a 360-degree sequence.
        """

        if (packet.data_len <= 8):
            # Ignore bad packets.
            return

        (num_frames, start_time) = struct.unpack("ll", packet.data)

        self.capture(8, num_frames, start_time)


    def do_capture_custom(self, packet):
        """
        Capture a custom sequence.
        """

        if (packet.data_len <= 14):
#.........这里部分代码省略.........
开发者ID:SpaceVR-O1,项目名称:OverviewOne,代码行数:103,代码来源:tk1_main.py

示例7: Board

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import run [as 别名]
#!/usr/bin/python
from board import Board
from player import Player
from agent import Agent
import time

start_time = time.time()
game_board = Board()
self_player = Player(0, game_board) #white player
enemy_player = Player(1, game_board) #black player


game_agent = Agent(self_player, enemy_player, game_board)

print game_agent.run(game_board)

print "Time: " + str(time.time() - start_time)
开发者ID:cannon10100,项目名称:Chess-AI,代码行数:19,代码来源:init.py

示例8: Handle

# 需要导入模块: from agent import Agent [as 别名]
# 或者: from agent.Agent import run [as 别名]
class Handle(object):
  """Agent environment handle.
  """
  def __init__(self, belt_a, belt_b, power=20, agent=None):
    self.belt_a, self.belt_b = belt_a, belt_b
    self.a, self.b = 0, 0
    self.power = power
    self.running = True
    if agent is None:
      self.agent = Agent()
    else:
      self.agent = agent

    self.state = None
    self.perceptions = None
    self.action = None
    
    # fix belts so that both have at least two appending -1
    self.belt_a.extend([-1, -1])
    self.belt_b.extend([-1, -1])

    # msg buffer
    self.msgs = []

  def step(self):
    """Run one step of agent; update handle parameters.
    """
    self.action = self.agent.run(*(
        self.belt_a[self.a],
        self.belt_a[self.a+1],
        self.belt_b[self.b],
        self.belt_b[self.b+1],
        self.power,))

    if self.action == "ADVANCE_A":
      self.a += 1
      self.power -= 1
    elif self.action == "ADVANCE_B":
      self.b += 1
      self.power -= 1
    elif self.action == "PICKUP_A":
      self.belt_a[self.a] = 0
      self.power -= 1
    elif self.action == "PICKUP_B":
      self.belt_b[self.b] = 0
      self.power -= 1
    elif "DROP_ITEM" in self.action:
      self.power -= 1
    elif "FILL_ITEM" in self.action:
      pass
    elif self.action == "STOP":
      self.running = False

  def run(self):
    """Continue to run agent until stopped."""
    while(self.running):
      self.perceptions = (
        self.belt_a[self.a],
        self.belt_a[self.a+1],
        self.belt_b[self.b],
        self.belt_b[self.b+1],
        self.power)
      self.msgs.append("INPUT PERCEPTION: %d %d %d %d %d" % self.perceptions)
      self.msgs.append(\
        "AGENT STATE: %s %s" % (self.agent.items, self.agent.hand))
      self.step()
      self.msgs.append("OUTPUT ACTION: %s" % self.action)
      self.msgs.append("")

    self.msgs.append("======")
    self.msgs.append("FINAL STATE: %s, %s" % (self.agent.items, self.agent.hand))
    self.msgs.append("FINAL SUM: %s" % sum(self.agent.items))

  def sum(self):
    return sum(self.agent.items)

  def report(self):
    """Return a list of strings as status report."""
    r = ["REPORT", "====="]
    r.append("INPUT PERCEPTION: %d %d %d %d %d" % self.perceptions)
    r.append("AGENT STATE: %s %s" % (self.agent.items, self.agent.hand))
    return r
开发者ID:andrewdyates,项目名称:CSE-630,代码行数:84,代码来源:handle.py


注:本文中的agent.Agent.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。