from bblist import * from schematic import schematic from formulate import solve, autosolve if __name__ == '__main__': # Another case study for the solver: an N-channel remote. # Build strategy is enforcing uC and LED to be together, while allowing # large bridges betwen battery and bat, as well as bat and uC. n = 7 ws = (10, 10, 2) problem = schematic(ws, name=("Remote-" + str(n))) lip = Lipo("LiPo") but = [] uc = [] led = [] for chan in range(1, n + 1): but = But("Button " + str(chan)) led = Led("LED " + str(chan)) uc = Micro("uC " + str(chan)) problem.addConnection(lip, 'PWR', but, 'B1', 3) problem.addConnection(but, 'B2', uc, 'PWR', 3) problem.addConnection(uc, 'OUT2', led, 'LED') # Call the solver, which positions the Bitblox correctly. fixed = autosolve(problem)
bank.append(But("Button 5")) bank.append(But("Button 6")) bank.append(Micro("uC 1")) bank.append(Micro("uC 2")) bank.append(Micro("uC 3")) bank.append(Micro("uC 4")) bank.append(Led("LED 1")) 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)
from bblist import * from schematic import schematic from formulate import solve, autosolve if __name__ == '__main__': # Another case study for the solver: button-battery-light serial circuit. ws = (3, 3, 2) problem = schematic(ws, name="Double LED") bat = Bat('Battery') but1 = But('Button 1') but2 = But('Button 2') led1 = Led('LED 1') led2 = Led('LED 2') problem.addConnection(bat, 'PWR', but1, 'B2') problem.addConnection(but1, 'B1', led1, 'LED') problem.addConnection(bat, 'PWR', but2, 'B2') problem.addConnection(but2, 'B1', led2, 'LED') # Call the simple solver, which positions the Bitblox correctly. solve(problem) # Draw the assembly resulting from the solution. problem.showSolution()
from bblist import * from schematic import schematic from formulate import solve, autosolve import pdb, traceback if __name__ == '__main__': try: # A simple case study for the solver: two buttons sharing a net. ws = (2, 2, 2) problem = schematic(ws, name="Two Buttons") butA = But('Button 1', color=(0, 0, 1)) butB = But('Button 2', color=(1, 0, 0)) problem.addConnection(butA, 'B1', butB, 'B1') # Fixed Button 1 at the origin with default orientation, as example. problem.fix((butA, 0, 0, 0, 0)) # Call the solver, which positions the Bitblox correctly. solve(problem) # Draw the assembly resulting from the solution. problem.showSolution() except Exception, e:
if __name__ == '__main__': # Another case study for the solver: button-battery-light serial circuit. lip = Lipo("LiPo") but1 = But("Button 1") but2 = But("Button 2") led1 = Led("LED 1") led2 = Led("LED 2") uc1 = Micro("uC 1") uc2 = Micro("uC 2") # A workspace is defined by a (x, y, z) tuple of available positions # in positional grid units. ws = (6, 3, 2) problem = schematic(ws, name = "Small Remote") problem.addConnection(lip, 'PWR', but1, 'B1') problem.addConnection(but1, 'B2', uc1, 'PWR') problem.addConnection(uc1, 'OUT2', led1, 'LED') problem.addConnection(lip, 'PWR', but2, 'B1') problem.addConnection(but2, 'B2', uc2, 'PWR') problem.addConnection(uc2, 'OUT2', led2, 'LED') # Call the solver, which positions the Bitblox correctly. solve(problem) # Draw the assembly resulting from the solution. problem.showSolution()
from bblist import * from schematic import schematic from formulate import solve, autosolve import pdb, traceback if __name__ == '__main__': 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') problem.addConnection(butA, 'B1', butB, 'B1') # Fixed Button 1 at the origin with default orientation, as example. problem.fix((butA, 0, 0, 0, 0)) # Call the solver, which positions the Bitblox correctly. solve(problem) # Draw the assembly resulting from the solution. problem.showSolution() except Exception, e:
from bblist import * from schematic import schematic from formulate import solve, autosolve import pdb, traceback if __name__ == '__main__': 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)
from formulate import solve, autosolve import random, sys if __name__ == '__main__': # Rob's 6 - channel remote with small batteries. # Note that there is no reason for the independent channels to # be connected (in fact, they should not be), so structural # blocks must be added for the solution to make sense. # Since this can easily be done algorithmically post-SAT, we do # it by hand to generate figures. n = 6 ws = (9, 9, 2) problem = schematic(ws, name = "Robmote") print "Making " + problem.name + " in " + str(ws) for chan in range(1, n+1): bat1 = Bat("Battery " + str(chan) + 'A') bat2 = Bat("Battery " + str(chan) + 'B') but = But("Button " + str(chan)) led = Led("LED " + str(chan)) uc = Micro("uC " + str(chan)) problem.addConnection(bat1, 'PWR', bat2, 'PWR', 3) problem.addConnection(bat2, 'PWR', but, 'B1', 3) problem.addConnection(but, 'B2', uc, 'PWR') problem.addConnection(uc, 'OUT2', led, 'LED') # Call the solver, which positions the Bitblox correctly. try: fixed = autosolve(problem)
import random if __name__ == '__main__': # Another case study for the solver: an N-pole filter. # For every pole, add a capacitor to the last output to ground, and # an inductor leading to the next output. # The connector mutation does not work in cases where Pycosat takes # too long to return (such as this) so we need to manually specify # the necessary connector blocks. n = 4 ws = (2 * n, 4, 2) problem = schematic(ws, name=("Filter-" + str(n))) lastInd = Inductor("Inductor 1") lastCap = Cap("Capacitor 1") lastGnd = Pass("Ground") problem.addConnection(lastInd, "I2", lastCap, "C1") problem.addConnection(lastCap, "C2", lastGnd, "P") for chan in range(2, n + 1): ind = Inductor("Inductor " + str(chan)) cap = Cap("Capacitor " + str(chan)) gnd = Pass("Ground " + str(chan)) problem.addConnection(lastInd, "I2", ind, 'I1') problem.expandLast() problem.addConnection(ind, "I2", cap, "C1") problem.addConnection(cap, "C2", gnd, "P")