remove python2
This commit is contained in:
parent
352dbeef06
commit
c25d7fb13e
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
numpy
|
101
sim.py
101
sim.py
@ -1,101 +0,0 @@
|
|||||||
import os
|
|
||||||
import numpy as np
|
|
||||||
import numpy.random as rnd
|
|
||||||
import sys
|
|
||||||
import importlib
|
|
||||||
import imp
|
|
||||||
import ctypes
|
|
||||||
import ctypes.util
|
|
||||||
from numpy.ctypeslib import ndpointer
|
|
||||||
import event_gen as eg
|
|
||||||
|
|
||||||
PPP=60
|
|
||||||
claim_types={'bronze':{'bw': 1, 'value': 2, 'damage':4, 'duration': 100, 'pr': 0.4},
|
|
||||||
'silver': {'bw': 3, 'value': 5, 'damage':6, 'duration': 50, 'pr': 0.3},
|
|
||||||
'gold':{'bw': 10, 'value': 30, 'damage':80, 'duration': 70, 'pr': 0.1}}
|
|
||||||
|
|
||||||
|
|
||||||
class Claim:
|
|
||||||
def __init__(self,ty,time):
|
|
||||||
self.ty = ty
|
|
||||||
self.bw=claim_types[ty]['bw']
|
|
||||||
self.val=claim_types[ty]['value']
|
|
||||||
self.dam=claim_types[ty]['damage']
|
|
||||||
self.dur=claim_types[ty]['duration']
|
|
||||||
self.init_time=time
|
|
||||||
self.end_time=time+self.dur
|
|
||||||
|
|
||||||
class Sim:
|
|
||||||
def __init__(self,bw):
|
|
||||||
self.queue=[]
|
|
||||||
self.bw=bw
|
|
||||||
self.free=bw
|
|
||||||
self.budget=(-1)*PPP*self.bw
|
|
||||||
|
|
||||||
def step(self, lista):
|
|
||||||
self.budget-=sum([self.queue[i].dam for i in range(len(self.queue)) if lista[i]==0])
|
|
||||||
self.queue = [self.queue[i] for i in range(len(self.queue)) if lista[i]==1]
|
|
||||||
|
|
||||||
def new(self, item):
|
|
||||||
if item.bw<=self.free:
|
|
||||||
self.queue.append(item)
|
|
||||||
|
|
||||||
def process(self,time):
|
|
||||||
for i in range(len(self.queue)-1,-1,-1):
|
|
||||||
if self.queue[i].end_time<=time:
|
|
||||||
self.budget+=self.queue[i].val
|
|
||||||
del self.queue[i]
|
|
||||||
self.free=self.bw
|
|
||||||
for item in self.queue:
|
|
||||||
self.free-=item.bw
|
|
||||||
|
|
||||||
def get_queue_list(self,time):
|
|
||||||
lista=[]
|
|
||||||
for item in self.queue:
|
|
||||||
lista.append([item.ty,item.end_time-time])
|
|
||||||
return lista
|
|
||||||
|
|
||||||
results={}
|
|
||||||
folder='Strats'
|
|
||||||
|
|
||||||
sys.path.append(folder)
|
|
||||||
strats=os.listdir(folder)
|
|
||||||
strats_py=[x.split('.')[0] for x in strats if x.split('.')[-1]=="py"]
|
|
||||||
#strats_py=['tut_mymy']
|
|
||||||
|
|
||||||
for _ in range(10):
|
|
||||||
events=eg.event_gen(2000)
|
|
||||||
"""
|
|
||||||
os.system('python event_gen.py >event1.txt')
|
|
||||||
with open('event1.txt') as inf:
|
|
||||||
for line in inf:
|
|
||||||
a=line.split()
|
|
||||||
# print a
|
|
||||||
if a:
|
|
||||||
events.append([int(a[0]),a[1]])
|
|
||||||
|
|
||||||
#print events
|
|
||||||
"""
|
|
||||||
for strat in strats_py:
|
|
||||||
mod=importlib.import_module(strat)
|
|
||||||
sim=Sim(max(0,mod.init_bw()))
|
|
||||||
for e in events:
|
|
||||||
[time,claim]=e
|
|
||||||
sim.process(time)
|
|
||||||
[new,lista]=mod.decision(claim, sim.get_queue_list(time))
|
|
||||||
sim.step(lista)
|
|
||||||
if new==1:
|
|
||||||
sim.new(Claim(claim,time))
|
|
||||||
sim.process(time+1000)
|
|
||||||
if not strat in results:
|
|
||||||
results[strat]=0
|
|
||||||
results[strat]+=sim.budget
|
|
||||||
for key in results:
|
|
||||||
results[key]/=10.0
|
|
||||||
print results
|
|
||||||
"""
|
|
||||||
strat=strats[0]
|
|
||||||
mod=importlib.import_module(strat)
|
|
||||||
for _ in range(10):
|
|
||||||
print mod.decision(1,[3,3])
|
|
||||||
"""
|
|
105
sim_p3.py
105
sim_p3.py
@ -2,69 +2,72 @@ import os
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.random as rnd
|
import numpy.random as rnd
|
||||||
import sys
|
import sys
|
||||||
import importlib
|
import importlib
|
||||||
#import imp
|
# import imp
|
||||||
import ctypes
|
import ctypes
|
||||||
import ctypes.util
|
import ctypes.util
|
||||||
from numpy.ctypeslib import ndpointer
|
from numpy.ctypeslib import ndpointer
|
||||||
import event_gen as eg
|
import event_gen as eg
|
||||||
|
|
||||||
PPP=60
|
|
||||||
claim_types={'bronze':{'bw': 1, 'value': 2, 'damage':4, 'duration': 100, 'pr': 0.4},
|
PPP = 60
|
||||||
'silver': {'bw': 3, 'value': 5, 'damage':6, 'duration': 50, 'pr': 0.3},
|
claim_types = {'bronze': {'bw': 1, 'value': 2, 'damage': 4, 'duration': 100, 'pr': 0.4},
|
||||||
'gold':{'bw': 10, 'value': 30, 'damage':80, 'duration': 70, 'pr': 0.1}}
|
'silver': {'bw': 3, 'value': 5, 'damage': 6, 'duration': 50, 'pr': 0.3},
|
||||||
|
'gold': {'bw': 10, 'value': 30, 'damage': 80, 'duration': 70, 'pr': 0.1}}
|
||||||
|
|
||||||
|
|
||||||
class Claim:
|
class Claim:
|
||||||
def __init__(self,ty,time):
|
def __init__(self, ty, time):
|
||||||
self.ty = ty
|
self.ty = ty
|
||||||
self.bw=claim_types[ty]['bw']
|
self.bw = claim_types[ty]['bw']
|
||||||
self.val=claim_types[ty]['value']
|
self.val = claim_types[ty]['value']
|
||||||
self.dam=claim_types[ty]['damage']
|
self.dam = claim_types[ty]['damage']
|
||||||
self.dur=claim_types[ty]['duration']
|
self.dur = claim_types[ty]['duration']
|
||||||
self.init_time=time
|
self.init_time = time
|
||||||
self.end_time=time+self.dur
|
self.end_time = time + self.dur
|
||||||
|
|
||||||
|
|
||||||
class Sim:
|
class Sim:
|
||||||
def __init__(self,bw):
|
def __init__(self, bw):
|
||||||
self.queue=[]
|
self.queue = []
|
||||||
self.bw=bw
|
self.bw = bw
|
||||||
self.free=bw
|
self.free = bw
|
||||||
self.budget=(-1)*PPP*self.bw
|
self.budget = (-1) * PPP * self.bw
|
||||||
|
|
||||||
def step(self, lista):
|
def step(self, lista):
|
||||||
self.budget-=sum([self.queue[i].dam for i in range(len(self.queue)) if lista[i]==0])
|
self.budget -= sum([self.queue[i].dam for i in range(len(self.queue)) if lista[i] == 0])
|
||||||
self.queue = [self.queue[i] for i in range(len(self.queue)) if lista[i]==1]
|
self.queue = [self.queue[i] for i in range(len(self.queue)) if lista[i] == 1]
|
||||||
|
|
||||||
def new(self, item):
|
def new(self, item):
|
||||||
if item.bw<=self.free:
|
if item.bw <= self.free:
|
||||||
self.queue.append(item)
|
self.queue.append(item)
|
||||||
|
|
||||||
def process(self,time):
|
def process(self, time):
|
||||||
for i in range(len(self.queue)-1,-1,-1):
|
for i in range(len(self.queue) - 1, -1, -1):
|
||||||
if self.queue[i].end_time<=time:
|
if self.queue[i].end_time <= time:
|
||||||
self.budget+=self.queue[i].val
|
self.budget += self.queue[i].val
|
||||||
del self.queue[i]
|
del self.queue[i]
|
||||||
self.free=self.bw
|
self.free = self.bw
|
||||||
for item in self.queue:
|
for item in self.queue:
|
||||||
self.free-=item.bw
|
self.free -= item.bw
|
||||||
|
|
||||||
def get_queue_list(self,time):
|
def get_queue_list(self, time):
|
||||||
lista=[]
|
lista = []
|
||||||
for item in self.queue:
|
for item in self.queue:
|
||||||
lista.append([item.ty,item.end_time-time])
|
lista.append([item.ty, item.end_time - time])
|
||||||
return lista
|
return lista
|
||||||
|
|
||||||
results={}
|
|
||||||
folder='Strats'
|
results = {}
|
||||||
|
folder = 'Strats'
|
||||||
|
|
||||||
sys.path.append(folder)
|
sys.path.append(folder)
|
||||||
strats=os.listdir(folder)
|
strats = os.listdir(folder)
|
||||||
strats_py=[x.split('.')[0] for x in strats if x.split('.')[-1]=="py"]
|
strats_py = [x.split('.')[0] for x in strats if x.split('.')[-1] == "py"]
|
||||||
#strats_py=['tut_mymy']
|
# strats_py=['tut_mymy']
|
||||||
|
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
events=eg.event_gen(2000)
|
events = eg.event_gen(2000)
|
||||||
"""
|
"""
|
||||||
os.system('python event_gen.py >event1.txt')
|
os.system('python event_gen.py >event1.txt')
|
||||||
with open('event1.txt') as inf:
|
with open('event1.txt') as inf:
|
||||||
@ -77,19 +80,21 @@ for _ in range(10):
|
|||||||
#print events
|
#print events
|
||||||
"""
|
"""
|
||||||
for strat in strats_py:
|
for strat in strats_py:
|
||||||
mod=importlib.import_module(strat)
|
mod = importlib.import_module(strat)
|
||||||
sim=Sim(max(0,mod.init_bw()))
|
sim = Sim(max(0, mod.init_bw()))
|
||||||
for e in events:
|
for e in events:
|
||||||
[time,claim]=e
|
[time, claim] = e
|
||||||
sim.process(time)
|
sim.process(time)
|
||||||
[new,lista]=mod.decision(claim, sim.get_queue_list(time))
|
[new, lista] = mod.decision(claim, sim.get_queue_list(time))
|
||||||
sim.step(lista)
|
sim.step(lista)
|
||||||
if new==1:
|
if new == 1:
|
||||||
sim.new(Claim(claim,time))
|
sim.new(Claim(claim, time))
|
||||||
sim.process(time+1000)
|
sim.process(time + 1000)
|
||||||
if not strat in results:
|
if not strat in results:
|
||||||
results[strat]=0
|
results[strat] = 0
|
||||||
results[strat]+=sim.budget
|
results[strat] += sim.budget
|
||||||
|
|
||||||
for key in results:
|
for key in results:
|
||||||
results[key]/=10.0
|
results[key] /= 10.0
|
||||||
|
|
||||||
print(results)
|
print(results)
|
||||||
|
Loading…
Reference in New Issue
Block a user