-
Notifications
You must be signed in to change notification settings - Fork 2
/
cbr.py
51 lines (37 loc) · 868 Bytes
/
cbr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import math
class Case:
def __init__(self):
self.data=[]
self.name=''
self.solution=[]
def f(self,x):
print x
def sim(self,cB):
#if len(cB.data)!=len(self.data):
# raise AssertionError('Data of different size')
add=0
diff=0
for i in range(len(self.data)):
diff=self.data[i]-cB.data[i]
add=add+(diff*diff)
return 1/(1+math.sqrt(add))
def __str__(self):
return self.name
class Library:
def __init__(self):
self.cases = []
def retrieveCase(self,newCase):
sim=-1
cCase= None
for case in self.cases:
nSim=newCase.sim(case)
#print str(case),nSim
if nSim>sim:
sim=nSim
cCase=case
return cCase
def transformSolution(self,newCase,oldCase):
newCase.solution=oldCase.solution
def solveCase(self,newCase):
oldCase=self.retrieveCase(newCase)
self.transformSolution(newCase,oldCase)