示例#1
0
    try:

        # A simple case study for the solver: two buttons sharing a net.
        ws = (3, 3, 3)
        problem = schematic(ws, name="Bridged Buttons")

        butA = But('Button 1')
        butB = But('Button 2')
        p = Pass('Pass')

        problem.addConnection(butA, 'B1', butB, 'B1', 5)
        # problem.addConnection(butA, 'B1', p, 'P')
        # problem.addConnection(p, 'P', butB, 'B1')

        # Fixed Button 1 at the origin with default orientation, as example.
        problem.fix((butA, 0, 0, 0, 0))

        # To test bridging, also fix Button 2 in a position which requires it.
        problem.fix((butB, 2, 2, 2, 2))

        # Call the solver, which positions the Bitblox correctly.
        expanded = autosolve(problem, tries=5)

        # Draw the assembly resulting from the solution.
        expanded.showSolution()

    except Exception, e:

        traceback.print_exc()
        pdb.post_mortem()
    bank.append(Led("LED 2"))
    bank.append(Led("LED 3"))
    bank.append(Led("LED 4"))
    bank.append(Led("LED 5")) 
    bank.append(Led("LED 6")) 
    bank.append(Bat("Small Bat 1"))
    bank.append(Bat("Small Bat 2"))

    problem = schematic(ws, name = ("Random-" + str(n)))

    for i in range(n):
        firstPick = random.randint(0, len(bank) - 1)
        secondPick = firstPick
        while secondPick == firstPick:
            secondPick = random.randint(0, len(bank) - 1)
        bb1 = bank[firstPick]
        bb2 = bank[secondPick]
        nets1 = bb1.listNets()
        nets2 = bb2.listNets()
        bb1Net = nets1[random.randint(0, len(nets1) - 1)]
        bb2Net = nets2[random.randint(0, len(nets2) - 1)]
        problem.addConnection(bb1, bb1Net, bb2, bb2Net, relax)
        print ("Added " + bb1.name + ', ' + bb1Net + ' to ' +
                bb2.name + ', ' + bb2Net)

    # Call the solver, which positions the Bitblox correctly.

    fixed = autosolve(problem)

    # Draw the assembly resulting from the solution.
    #fixed.showSolution() 
    try:

        # A simple case study for the solver: two buttons sharing a net.
        ws = (2, 2, 2)
        problem = schematic(ws)

        butA = But('Button 1')
        butB = But('Button 2')
        p = Pass('Pass')

        problem.addConnection(butA, 'B1', butB, 'B1', 1)
        # problem.addConnection(butA, 'B1', p, 'P')
        # problem.addConnection(p, 'P', butB, 'B1')

        # Fixed Button 1 at the origin with default orientation, as example.
        problem.fix((butA, 0, 0, 0, 0))

        # To test bridging, also fix Button 2 in a position which requires it.
        problem.fix((butB, 1, 1, 0, 2))

        # Call the solver, which positions the Bitblox correctly.
        expanded = autosolve(problem)

        # Draw the assembly resulting from the solution.
        expanded.showSolution()

    except Exception, e:

        traceback.print_exc()
        pdb.post_mortem()