Esempio n. 1
0
def test_nonlocking():
    '''Test for lockups'''
    def test(clk, enable, d, set, dset, width):
        # Check for 11...1 -> 11...1
        set.next = True
        dset.next = intbv(-1)[width:]
        enable.next = True
        clk.next = 1
        yield delay(10)
        clk.next = 0
        set.next = False
        yield delay(10)
        clk.next = 1
        yield delay(10)
        clk.next = 0
        yield delay(10)
        assert d.val != intbv(-1)[width:]
        # Check for 00...0 -> 00...0
        set.next = True
        dset.next = intbv(0)[width:]
        enable.next = True
        clk.next = 1
        yield delay(10)
        clk.next = 0
        set.next = False
        yield delay(10)
        clk.next = 1
        yield delay(10)
        clk.next = 0
        yield delay(10)
        assert d.val != intbv(0)[width:]
        raise StopSimulation

    for reverse, width in combinations([True, False], TESTED_WIDTHS):
        clk = Signal(bool(0))
        enable = Signal(True)
        d = Signal(intbv(0)[width:])
        set = Signal(False)
        dset = Signal(intbv(0)[width:])
        lfsr = LFSR(clk, enable, d, set, dset, width=width, 
                    non_locking=True, reverse=reverse)
        chk = test(clk, enable, d, set, dset, width)
        print 'nonlocking ', width, reverse
        sim = Simulation(lfsr, chk)
        sim.run(quiet=1)

    for direction, width in combinations([0, 1], TESTED_WIDTHS):
        clk = Signal(bool(0))
        enable = Signal(True)
        d = Signal(intbv(0)[width:])
        dir = Signal(bool(direction))
        set = Signal(False)
        dset = Signal(intbv(0)[width:])
        lfsr = reversible_LFSR(clk, enable, d, dir, set, dset, 
                               width=width, non_locking=True)
        chk = test(clk, enable, d, set, dset, width)
        print 'nonlocking2 ', width, direction
        sim = Simulation(lfsr, chk)
        sim.run(quiet=1)
Esempio n. 2
0
def test_period():
    '''Test for correct period'''
    def test(clk, enable, d, set, dset, width):
        set.next = True
        dset.next = intbv(0)[width:]
        enable.next = False
        yield posedge(clk)
        set.next = False
        enable.next = True
        yield posedge(clk)
        used = {}
        while True:
            if int(d.val) in used:
                actual = used.keys()
                actual.sort()
                expected = range(2 ** width - 1)
                assert actual == expected
                raise StopSimulation
            used[int(d.val)] = 1
            yield posedge(clk)

    for non_locking, reverse, width in combinations(
        [True, False], [True, False], TESTED_WIDTHS_PERIOD):
        clk = Signal(False)
        enable = Signal(False)
        d = Signal(intbv(0)[width:])
        set = Signal(False)
        dset = Signal(intbv(0)[width:])
        lfsr = LFSR(clk, enable, d, set, dset, width=width, 
                    non_locking=non_locking, reverse=reverse)
        chk = test(clk, enable, d, set, dset, width)
        clkgen_inst = clockGen(clk)
        print 'period', non_locking, reverse, width
        sim = Simulation(clkgen_inst, lfsr, chk)
        sim.run(quiet=1)

    for non_locking, direction, width in combinations(
        [True, False], [0, 1], TESTED_WIDTHS_PERIOD):
        clk = Signal(bool(0))
        enable = Signal(False)
        d = Signal(intbv(0)[width:])
        set = Signal(bool(0))
        dset = Signal(intbv(0)[width:])
        dir = Signal(bool(direction))
        lfsr = reversible_LFSR(clk, enable, d, dir, set, dset, width=width, 
                               non_locking=non_locking)
        chk = test(clk, enable, d, set, dset, width)
        print 'period2', non_locking, direction, width
        sim = Simulation(lfsr, chk)
        sim.run(quiet=1)
Esempio n. 3
0
 def runCombos(self):
     starttime=time.time()
     names = []
     classSize=[]
     stu = []
     for i in self.p3.names:
         names.append(i.get())
     for z in self.p4.studentsper:
         stu.append(int(z.get()))
     roomList, roomCount = importRooms.scan(self.p3.roomSheet.get())
     combos = []
     sizes=[]
     y = 0
     for x,studentsper in zip(self.returns,stu):
         combos.append(combinations.combinations(x[1], int(self.p4.entries[y].get()) ,x[0] ,roomCount,studentsper))
         sizes.append(int(self.p4.entries[y].get()))
         y+=1
     for printer in combos:
         print(len(printer))
     finalRoomCombo,finalStudentAssignments,LeaderDays=sort.Sorter([m[0] for m in self.returns],combos,names,sizes,roomList,[n[1] for n in self.returns],stu)
     print(time.time()-starttime)
     #assign the rooms
     for subj,subject in zip(finalRoomCombo,names):
         for group in subj:
             roomList[group].taken=True
     leaderAssignments,leaderRooms=assign.assignLeaders(self.leaderData,LeaderDays,roomList,sizes,finalRoomCombo)
     #print(time.time()-starttime)
     #f2=open('variables2.txt','wb')
     #pickle.dump([roomList,leaderAssignments,leaderRooms])
     #assign everything
     data=[]
     for n in self.returns:
         data.append(n)
     assignEverything.assign(roomList,finalRoomCombo,finalStudentAssignments,leaderRooms,leaderAssignments,names)
Esempio n. 4
0
    def test_combinations(self):
        self.assertEqual(combinations.combinations('HACK', '2'), '''A
C
H
K
AC
AH
AK
CH
CK
HK''')
Esempio n. 5
0
 def generate_haps(self, pheno_seq):
   """ pheno_seq example
 
               |<------- 2 alleles --------->|
               
                           |<- g_size = 4 ->|                
                           
               [[1, 2, 1], [0, 0, 1, 1, 1, 1]]
                    ^               
                    |_ 2 copies of allele 1      """
                    
   allele_list = self.generate_allele_list(pheno_seq)
   hap_list = combinations(allele_list)
   return  hap_list
Esempio n. 6
0
def test_reverse():
    '''Test for correct reversing'''
    def test(clk, enable0, enable1, d0, d1, set0, set1, 
             dset0, dset1, width):
        enable0.next = True
        enable1.next = True
        set0.next = True
        set1.next = True
        dset0.next = intbv(0)[width:]
        dset1.next = intbv(0)[width:]
        clk.next = True
        yield delay(10)
        set0.next = False
        set1.next = False
        clk.next = False
        yield delay(10)
        seq0 = []
        seq1 = []
        for i in range(2 ** width):
            seq0.append(int(d0.val))
            seq1.append(int(d1.val))
            clk.next = True
            yield delay(10)
            clk.next = False
            yield delay(10)
        seq1.reverse()
        assert seq0 == seq1
        raise StopSimulation

    for non_locking, width in combinations(
        [True, False], TESTED_WIDTHS_PERIOD):
        clk = Signal(bool(0))
        enable0 = Signal(bool(0))
        enable1 = Signal(bool(0))
        d0 = Signal(intbv(0)[width:])
        d1 = Signal(intbv(0)[width:])
        set0 = Signal(bool(0))
        set1 = Signal(bool(0))
        dset0 = Signal(intbv(0)[width:])
        dset1 = Signal(intbv(0)[width:])
        lfsr0 = LFSR(clk, enable0, d0, set0, dset0, width=width, 
                     non_locking=non_locking, reverse=False)
        lfsr1 = LFSR(clk, enable1, d1, set1, dset1, width=width, 
                     non_locking=non_locking, reverse=True)
        chk = test(clk, enable0, enable1, d0, d1, 
                   set0, set1, dset0, dset1, width)
        print 'reverse ', non_locking, width
        sim = Simulation(lfsr0, lfsr1, chk)
        sim.run(quiet=1)
Esempio n. 7
0
def main():
    # Пробуем получить из базы последний обработанный запрос
    last_record = session.query(Suggests).order_by(
        Suggests.number.desc()).first()
    if last_record:
        number = last_record.number
        query = last_record.query
    else:
        number, query = None, None

    # Инициализируем генератор стартовых слов
    generator = combinations(config.COMBINATIONS_STRING,
                             config.MIN_LENGTH_R,
                             config.MAX_LENGTH_R,
                             number=number,
                             query=query)

    with Pool(config.THREAD_COUNT) as p:
        p.map(get_suggest, generator)
Esempio n. 8
0
def test_reversible():
    '''Test for correct reversing behavior in reversible lfsrs'''
    def test(clk, enable, d, dir, set, dset, width, l):
        set.next = True
        dset.next = intbv(0)[width:]
        enable.next = True
        clk.next = 1
        yield delay(10)
        clk.next = 0
        set.next = False
        yield delay(10)
        clk.next = 1
        yield delay(10)
        for i in range(l):
            v0 = d.val
            clk.next = 0
            yield delay(10)
            clk.next = 1
            yield delay(10)
        clk.next = 0
        dir.next = not dir
        yield delay(10)
        clk.next = 1
        yield delay(10)
        assert v0 == d.val
        raise StopSimulation

    for non_locking, direction, width, l in combinations(
        [True, False], [0, 1], 
        TESTED_WIDTHS_REVERSIBLE, TESTED_LEN_REVERSIBLE):
        clk = Signal(bool(0))
        enable = Signal(bool(0))
        d = Signal(intbv(0)[width:])
        dir = Signal(bool(direction))
        set = Signal(bool(0))
        dset = Signal(intbv(0)[width:])
        lfsr = reversible_LFSR(clk, enable, d, dir, set, dset, 
                               width=width, non_locking=non_locking)
        chk = test(clk, enable, d, dir, set, dset, width, l)
        print 'reversible ', non_locking, direction, width, l
        sim = Simulation(lfsr, chk)
        sim.run(quiet=1)
Esempio n. 9
0
 def runCombos(self):
     starttime = time.time()
     names = []
     classSize = []
     stu = []
     for i in self.p3.names:
         names.append(i.get())
     for z in self.p4.studentsper:
         stu.append(int(z.get()))
     roomList, roomCount = importRooms.scan(self.p3.roomSheet.get())
     combos = []
     sizes = []
     y = 0
     for x, studentsper in zip(self.returns, stu):
         combos.append(combinations.combinations(x[1], int(self.p4.entries[y].get()), x[0], roomCount, studentsper))
         sizes.append(int(self.p4.entries[y].get()))
         y += 1
     for printer in combos:
         print(len(printer))
     finalRoomCombo, finalStudentAssignments, LeaderDays = sort.Sorter(
         [m[0] for m in self.returns], combos, names, sizes, roomList, [n[1] for n in self.returns], stu
     )
     print(time.time() - starttime)
     # assign the rooms
     for subj, subject in zip(finalRoomCombo, names):
         for group in subj:
             roomList[group].taken = True
     leaderAssignments, leaderRooms = assign.assignLeaders(
         self.leaderData, LeaderDays, roomList, sizes, finalRoomCombo
     )
     # print(time.time()-starttime)
     # f2=open('variables2.txt','wb')
     # pickle.dump([roomList,leaderAssignments,leaderRooms])
     # assign everything
     data = []
     for n in self.returns:
         data.append(n)
     assignEverything.assign(
         roomList, finalRoomCombo, finalStudentAssignments, leaderRooms, leaderAssignments, names
     )
Esempio n. 10
0
def chances(runonce = 0):
    ''' How many combinations are there?
        What is the chance to win any money?
    '''
    win = '? zł'
    if runonce == 0:
        cb = combinations.combinations(49, 6)
        cb = str(cb)
        print('Ilość kombinacji w:\n')
        print('Lotto: ' + combinations.splitthousands(cb, '.'))
        cb = combinations.combinations(42, 5)
        cb = str(cb)
        print('Mini Lotto: ' + combinations.splitthousands(cb, '.'))
        cb = int(combinations.combinations(80, 10) / combinations.combinations(20, 10))
        cb = str(cb)
        print('Multi Multi: ' + combinations.splitthousands(cb, '.'))
        input('Wciśnij ENTER: ')
    running2 = True
    while running2:
        try:
            clearscreen()
            print('Obliczanie prawdopodobieństwa wygranej.')
            print('-------------------------------')
            print('1. Lotto')
            print('2. Mini Lotto')
            print('3. Multi Multi')
            print('q - wyjście do głównego menu')
            game = input('Wybierz grę: ')
            if game == 'q':
                return game
            if game != '' and int(game) in range(1, 4):
                game = int(game)
                if game == 1: # Lotto
                    gamename = 'Lotto'
                    nums = 49
                    start = 3
                    stop = 7
                    numsdrawed = 6
                    running2 = False
                if game == 2: # Mini Lotto
                    gamename = 'Mini Lotto'
                    nums = 42
                    start = 3
                    stop = 6
                    numsdrawed = 5
                    running2 = False
                if game == 3: # Multi Multi
                    gamename = 'Multi Multi'
                    nums = 80
                    running2 = False
                    running3 = True
                    while running3:
                        numsdrawed = input('Podaj ilość typowanych liczb (1 do 10): ')
                        try:
                            if int(numsdrawed) in range(1, 11):
                                numsdrawed = int(numsdrawed)
                                running3 = False
                                if numsdrawed >= 5 and numsdrawed <= 7:
                                    start = 3
                                elif numsdrawed >= 2 and numsdrawed <= 4:
                                    start = 2
                                elif numsdrawed == 1:
                                    start = 1
                                else:
                                    start = 4
                                stop = numsdrawed + 1
                                machinedrawed = 20
                        except:
                            running3 = True
                if game != 3:
                    machinedrawed = numsdrawed
        except:
            print('Wprowadzono błędne dane!')
    clearscreen()
    print('Prawdopodobieństwo trafienia w '+ gamename)
    print('Typowano ' + str(numsdrawed) + ' z ' +str(nums))
    print('-------------------------------')
    running = True
    numsmatched = numsdrawed
    print('Trafiono:')
    while running:
        try:
            if numsdrawed is not None and numsdrawed in range(start, stop):
                if gamename == 'Multi Multi' and numsdrawed == 10 and numsmatched == 10:
                    win = '250 000 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 10 and numsmatched == 9:
                    win = '10 000 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 10 and numsmatched == 8:
                    win = '520 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 10 and numsmatched == 7:
                    win = '140 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 10 and numsmatched == 6:
                    win = '12 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 10 and numsmatched == 5:
                    win = '4 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 10 and numsmatched == 4:
                    win = '2 zł'

                if gamename == 'Multi Multi' and numsdrawed == 9 and numsmatched == 9:
                    win = '70 000 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 9 and numsmatched == 8:
                    win = '2 000 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 9 and numsmatched == 7:
                    win = '300 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 9 and numsmatched == 6:
                    win = '42 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 9 and numsmatched == 5:
                    win = '8 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 9 and numsmatched == 4:
                    win = '2 zł'

                if gamename == 'Multi Multi' and numsdrawed == 8 and numsmatched == 8:
                    win = '22 000 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 8 and numsmatched == 7:
                    win = '600 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 8 and numsmatched == 6:
                    win = '60 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 8 and numsmatched == 5:
                    win = '20 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 8 and numsmatched == 4:
                    win = '4 zł'

                if gamename == 'Multi Multi' and numsdrawed == 7 and numsmatched == 7:
                    win = '6 000 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 7 and numsmatched == 6:
                    win = '200 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 7 and numsmatched == 5:
                    win = '20 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 7 and numsmatched == 4:
                    win = '4 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 7 and numsmatched == 3:
                    win = '2 zł'

                if gamename == 'Multi Multi' and numsdrawed == 6 and numsmatched == 6:
                    win = '1 300 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 6 and numsmatched == 5:
                    win = '120 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 6 and numsmatched == 4:
                    win = '8 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 6 and numsmatched == 3:
                    win = '2 zł'

                if gamename == 'Multi Multi' and numsdrawed == 5 and numsmatched == 5:
                    win = '700 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 5 and numsmatched == 4:
                    win = '20 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 5 and numsmatched == 3:
                    win = '4 zł'

                if gamename == 'Multi Multi' and numsdrawed == 4 and numsmatched == 4:
                    win = '84 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 4 and numsmatched == 3:
                    win = '8 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 4 and numsmatched == 2:
                    win = '2 zł'

                if gamename == 'Multi Multi' and numsdrawed == 3 and numsmatched == 3:
                    win = '54 zł'
                elif gamename == 'Multi Multi' and numsdrawed == 3 and numsmatched == 2:
                    win = '2 zł'

                if gamename == 'Multi Multi' and numsdrawed == 2 and numsmatched == 2:
                    win = '16 zł'

                if gamename == 'Multi Multi' and numsdrawed == 1 and numsmatched == 1:
                    win = '4 zł'

                cb = combinations.matched(nums, numsdrawed, numsmatched, machinedrawed)
                cb = str(cb)
                print(str(numsmatched) + ': ' + '1:' + combinations.splitthousands(cb,'.') + ' (' + win + ')')
                numsmatched = numsmatched - 1
                win = '? zł'
                if numsmatched == start - 1:
                    running = False
        except:
            print('Wprowadzono błędne dane!')
    input('Wciśnij ENTER: ')
    clearscreen()
    chances(1)
Esempio n. 11
0
import time
#import excel file, print data
starttime=time.time()
import studentImport
blah=[]
datas=[]
data,times = studentImport.scan('/home/jasper/pilot/data.xls','Calc II')
data2,times2 = studentImport.scan('/home/jasper/pilot/data2.xls','Chem I')
import importRooms
rooms,roomCount=importRooms.scan('/home/jasper/pilot/rooms.xlsx')
blah.append(times)
blah.append(times2)
datas.append(data)
datas.append(data2)
import combinations
combos=[]
combos.append(combinations.combinations(blah[0],8,data,roomCount))
combos.append(combinations.combinations(blah[1],10,data2,roomCount))
print(len(combos[0]))
print(len(combos[1]))

import sort
finalCombo,finalAssignments,finalWaitList=sort.Sorter(datas,combos,['Calc II','Chem I'],[8,10],rooms,blah)
print(len(finalCombo))
#determine which finalCombo fits the leader availability the best

#leaderData=leaderImport.scan()

#import assign

Esempio n. 12
0
def test_combinations(value: List[Any], expected_result: List[List]):
    actual_result = combinations(*value)
    assert actual_result == expected_result