quantum

641 days ago by ryanmfw

import random class s(object): slot_list = [] total_m = 0 total_t = 0 a_type = ['m','t','n'] def __init__(self): self.open=True self.time_left = 0 self.a_type = 'n' #self.change_state() s.slot_list.append(self) def update(self): if not self.open: self.time_left -= 1 if self.time_left == 0: self.open = True self.a_type = 'n' def change_state(self): self.open = False self.time_left = 10 def send(self, receiver, a_type): self.change_state() self.a_type = a_type if a_type == 'm': s.total_m += 1 if a_type == 't': s.total_t +=1 for slot in receiver.slots: if slot.open: fslot = slot break fslot.recv(receiver, a_type) def recv(self, receiver, a_type): self.a_type = a_type self.change_state() @classmethod def update_all(s): for slot in s.slot_list: slot.update() class base(object): def __init__(self): self.slots = [s() for x in range(5)] self.__class__.member_list.append(self) @classmethod def get_open_slot_count(cls): count = 0 for b in cls.member_list: count += sum([slot.open and 1 or 0 for slot in b.slots]) return count @classmethod def get_open_slots(cls): slots = [] for x in cls.member_list: slots += x.slots return slots def send(self,rec,a_type): for slot in self.slots: if slot.open: fslot = slot break fslot.send(rec, a_type) class ba(base): member_list = [] class p(base): member_list = [] def __init__(self): super(p,self).__init__() self.t_owed = random.randint(-2,5) @classmethod def can_send_most(cls): return sorted(cls.member_list,key=lambda p: p.t_owed,reverse=True) class bu(base): member_list = [] ba_list = [] p_list = [] bu_list = [] total_slots_free = 0 total_slots = 0 for x in range(90): if x%2==0 and x<=10: ba_list.append([ba() for y in range(15)]) bu_list.append([bu() for y in range(55)]) p_list.append([p() for y in range(25)]) s.update_all() for proc in p.member_list: while proc.t_owed > 0 and sum([slot.open and 1 or 0 for slot in proc.slots])>0: buy = [] for b in bu.member_list: if sum([slot.open and 1 or 0 for slot in b.slots])>0: buy += [b] by = random.choice(buy) #by = random.choice(bu.get_open_slots()) proc.send(by,'t') proc.t_owed -=1 while proc.t_owed <= 0 and sum([slot.open and 1 or 0 for slot in proc.slots])>0: banks = [] for b in ba.member_list: if sum([slot.open and 1 or 0 for slot in b.slots])>0: banks += [b] ban = random.choice(banks) ban.send(proc,'m') proc.t_owed +=3 total_slots_free += p.get_open_slot_count() total_slots += sum([len(l.slots) for l in p.member_list]) print ba.get_open_slot_count() print p.get_open_slot_count() print bu.get_open_slot_count() print ",".join([str(pr.t_owed) for pr in p.can_send_most()]) print s.total_m print s.total_t print len(p.member_list) print sum([len(l.slots) for l in p.member_list]) print total_slots_free/total_slots 
       
258
3
1095
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,\
3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,\
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,\
1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0
1642
4903
150
750
26/1275
258
3
1095
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1642
4903
150
750
26/1275