Exemplo n.º 1
0
def test_reverseMDP(plot=False):
    greed = 0.9
    phobia = 0.1
    angStep = 1
    downsample = int(numpy.floor(3 / angStep))
    xPos, yPos = utils.hexFromDia(25, pitch=22.4)
    seed = 1
    rg = RobotGrid(stepSize=angStep, epsilon=epsilon, seed=seed)

    for robotID, (x, y) in enumerate(zip(xPos, yPos)):
        rg.addRobot(robotID, str(robotID), [x, y, 0], hasApogee)
    rg.setCollisionBuffer(collisionBuffer)
    rg.initGrid()
    for rID in rg.robotDict:
        robot = rg.getRobot(rID)
        robot.setXYUniform()
    assert rg.getNCollisions() > 10

    rg.decollideGrid()

    for robot in rg.robotDict.values():
        robot.setDestinationAlphaBeta(0, 180)
    assert rg.getNCollisions() == 0
    rg.pathGenMDP(greed, phobia)

    if plot:
        utils.plotPaths(rg, downsample=downsample, filename="reverseMDP.mp4")
Exemplo n.º 2
0
def test_fatty(plot=False):
    xPos, yPos = utils.hexFromDia(11, pitch=22.4)
    print("n robots", len(xPos))
    angStep = 0.1
    greed = 0.8
    phobia = 0.2
    collisionBuffer = 4
    downsample = int(numpy.floor(3 / angStep))
    rg = RobotGrid(stepSize=angStep, epsilon=epsilon, seed=1)

    for robotID, (x, y) in enumerate(zip(xPos, yPos)):
        rg.addRobot(robotID, str(robotID), [x, y, 0], hasApogee)
    rg.setCollisionBuffer(collisionBuffer)
    rg.initGrid()
    for rID in rg.robotDict:
        robot = rg.getRobot(rID)
        robot.setXYUniform()
        robot.setDestinationAlphaBeta(90, 180)
    # assert rg.getNCollisions() > 10

    rg.decollideGrid()

    rg.pathGenMDP(greed, phobia)

    # rg.smoothPaths(3)
    # rg.simplifyPaths()
    # rg.verifySmoothed()
    if plot:
        utils.plotPaths(rg, downsample=downsample, filename="fatty.mp4")
Exemplo n.º 3
0
def test_forwardMDP(plot=False):
    xPos, yPos = utils.hexFromDia(25, pitch=22.4)
    seed = 1
    rg = RobotGrid(stepSize=angStep, epsilon=epsilon, seed=seed)

    for robotID, (x, y) in enumerate(zip(xPos, yPos)):
        rg.addRobot(robotID, str(robotID), [x, y, 0], hasApogee)
    rg.setCollisionBuffer(collisionBuffer)
    rg.initGrid()
    for rID in rg.robotDict:
        robot = rg.getRobot(rID)
        robot.setXYUniform()
    assert rg.getNCollisions() > 10

    rg.decollideGrid()
    print("N collisions 1", rg.getNCollisions())

    for robot in rg.robotDict.values():
        robot.setDestinationAlphaBeta(robot.alpha, robot.beta)
        robot.setAlphaBeta(0, 180)
    print("N collisions 2", rg.getNCollisions())
    # assert rg.getNCollisions() == 0
    rg.pathGenMDP(0.9, 0.1)
    if plot:
        utils.plotPaths(rg, filename="forwardMDP.mp4")
Exemplo n.º 4
0
def test_initialConfigs(plot=False):

    xPos, yPos = utils.hexFromDia(21, pitch=22.4)
    angStep = 0.1
    greed = 0.8
    phobia = 0.2
    downsample = int(numpy.floor(10 / angStep))
    rg = RobotGrid(stepSize=angStep, epsilon=epsilon, seed=1)
    for robotID, (x, y) in enumerate(zip(xPos, yPos)):
        rg.addRobot(robotID, str(robotID), [x, y, 0], hasApogee)
    rg.setCollisionBuffer(collisionBuffer)
    rg.initGrid()
    for rID in rg.robotDict:
        robot = rg.getRobot(rID)
        robot.setXYUniform()
    assert rg.getNCollisions() > 10
    if plot:
        utils.plotOne(-1, rg, figname="angStepO.png", isSequence=False)

    rg.decollideGrid()
    for robot in rg.robotDict.values():
        robot.setDestinationAlphaBeta(0, 180)
    if plot:
        utils.plotOne(-1, rg, figname="angStepD.png", isSequence=False)
    rg.pathGenMDP(greed, phobia)
    if plot:
        utils.plotOne(-1, rg, figname="angStepE.png", isSequence=False)
    if plot:
        utils.plotPaths(rg, downsample=downsample, filename="init.mp4")
Exemplo n.º 5
0
def getGrid(angStep, cbuff, seed, nDia):
    rg = RobotGrid(stepSize=angStep,
                   collisionBuffer=cbuff,
                   epsilon=angStep * 2,
                   seed=seed)
    xPos, yPos = xPos, yPos = utils.hexFromDia(nDia, pitch=22.4, rotAngle=90)
    for robotID, (x, y) in enumerate(zip(xPos, yPos)):
        rg.addRobot(robotID, x, y, hasApogee)
    rg.initGrid()
    for robot in rg.robotDict.values():
        robot.setXYUniform()
        robot.setDestinationAlphaBeta(10, 170)

    rg.decollideGrid()
    # print("nCollisions in getGrid", rg.getNCollisions())
    return rg
Exemplo n.º 6
0
def test_unevenCBs(plot=False):
    hasApogee = True
    greed = 0.8
    phobia = 0.2

    xPos, yPos = utils.hexFromDia(17, pitch=22.4)
    seed = 1
    # cb = 2.5
    cs = 0.04
    step = 0.1  # degrees per step in kaiju's rough path
    smoothPts = 10  # width of velocity smoothing window
    eps = step * 2.2
    # downsample = int(numpy.floor(50 / step))
    rg = RobotGrid(stepSize=step, epsilon=eps, seed=seed)

    for robotID, (x, y) in enumerate(zip(xPos, yPos)):
        rg.addRobot(robotID,
                    str(robotID), [x, y, 0],
                    hasApogee,
                    collisionBuffer=numpy.random.uniform(1.5, 3.5))
    rg.initGrid()
    for rID in rg.robotDict:
        robot = rg.getRobot(rID)
        robot.setXYUniform()
    assert rg.getNCollisions() > 10

    rg.decollideGrid()

    for robot in rg.robotDict.values():
        robot.setDestinationAlphaBeta(0, 180)
    assert rg.getNCollisions() == 0
    tstart = time.time()
    rg.pathGenMDP(greed, phobia)
    print("pathgen took", time.time() - tstart)
    rg.smoothPaths(smoothPts)
    rg.simplifyPaths()
    rg.shrinkCollisionBuffer(cs)
    rg.verifySmoothed()

    assert rg.smoothCollisions == 0
    print("n smooth collisions", rg.smoothCollisions)

    if plot:
        for r in rg.robotDict.values():
            utils.plotTraj(r, "unevenCBs", dpi=250)
        utils.plotPaths(rg, downsample=3, filename="unevenCBs.mp4")
Exemplo n.º 7
0
def test_setMDP(plot=False):

    greed = 0.8
    phobia = 0.2
    xPos, yPos = utils.hexFromDia(45, pitch=22.4)
    print("using ", len(xPos), "robots")
    # collisionBuffer = 3
    angStep = 0.5
    collisionBuffer = 3
    downsample = int(numpy.floor(3 / angStep))
    for seed in range(100):
        rg = RobotGrid(stepSize=angStep, epsilon=epsilon, seed=seed)

        for robotID, (x, y) in enumerate(zip(xPos, yPos)):
            rg.addRobot(robotID, str(robotID), [x, y, 0], hasApogee)
        rg.setCollisionBuffer(collisionBuffer)
        rg.initGrid()
        for rID in rg.robotDict:
            robot = rg.getRobot(rID)
            robot.setXYUniform()
        assert rg.getNCollisions() > 10

        rg.decollideGrid()

        for robot in rg.robotDict.values():
            robot.setDestinationAlphaBeta(90, 180)
        assert rg.getNCollisions() == 0
        rg.pathGenMDP(greed, phobia)

        deadlockedRobots = []
        for r in rg.robotDict.values():
            # if not r.onTargetVec[-1]:
            if r.score() > 0:
                deadlockedRobots.append(r.id)
        if len(deadlockedRobots):
            print("seed", seed, "failed with these", deadlockedRobots, "in ",
                  rg.nSteps)
            break
        else:
            print("seed", seed, "didn't fail", rg.nSteps, " taken to solve")

    if plot:
        utils.plotPaths(rg,
                        downsample=downsample,
                        filename="reverseSetMDP.mp4")
Exemplo n.º 8
0
def test_tofile(plot=False):
    xPos, yPos = utils.hexFromDia(37, pitch=22.4, rotAngle=90)
    print("n robots", len(xPos))
    angStep = 1
    greed = 0.8
    phobia = 0.2
    downsample = int(numpy.floor(3 / angStep))
    rg = RobotGrid(stepSize=angStep, epsilon=epsilon, seed=1)

    for robotID, (x, y) in enumerate(zip(xPos, yPos)):
        rg.addRobot(robotID, str(robotID), [x, y, 0], hasApogee)
    rg.setCollisionBuffer(collisionBuffer)
    rg.initGrid()
    for rID in rg.robotDict:
        robot = rg.getRobot(rID)
        robot.setXYUniform()
    assert rg.getNCollisions() > 10

    rg.decollideGrid()
    for robot in rg.robotDict.values():
        robot.setDestinationAlphaBeta(10, 170)
    rg.pathGenMDP(greed, phobia)
    # rg.smoothPaths(3)
    # rg.simplifyPaths()
    # rg.verifySmoothed()
    # t1 = time.time()
    # rg.summaryJSON("json.txt")
    # print("json took", (time.time()-t1))

    # t1 = time.time()
    # rg.summaryPickle("rg.pkl")
    # print("pickle took", (time.time()-t1))

    # t1 = time.time()
    # g = json.load(open("json.txt", "r"))
    # print("json load took", (time.time()-t1))

    # t1 = time.time()
    # g = pickle.load(open("rg.pkl", "rb"))
    # print("pickle load took", (time.time()-t1))
    if plot:
        utils.plotOne(-1, rg, figname="tofile.png", isSequence=False)
Exemplo n.º 9
0
def getValidAssignments(seed):
    """seed is the random seed with which to initialze the RobotGrid

    return dictionary keyed by positioner id with the coordinates of the
    metrology fiber.  These represent valid (non-collided) xy Fiber positions
    for each robot
    """
    rg = RobotGrid(seed=seed)
    for ii, (xp, yp) in enumerate(zip(xCoords, yCoords)):
        rg.addRobot(robotID=ii, xPos=xp, yPos=yp)
    rg.initGrid()
    # give all robots an initial (radom) target configuration
    for robot in rg.robotDict.values():
        # assigns a robot a target picked uniformly in xy
        # from its patrol annulus
        robot.setXYUniform()
    # decollide any colliding robots so that we have a completely
    # non-colliding target configuration
    rg.decollideGrid()
    targetPos = {}
    for robot in rg.robotDict.values():
        targetPos[robot.id] = robot.metFiberPos[:-1]  # xy coord, drop the z
    return targetPos