from scipy import optimize as opt
from copy import deepcopy
import sys as sy
-
-
+import cv as cv
+import cv2 as cv2
error = 0.1
epsilon = 1E-10
vrate = 0.8
p = 0.7
coteCarre = 50
-distanceEmmissionMax = 30
+distanceEmmissionMax = 20
nbiter = 1000
POS = 1
POS_NUL = 2
#lg= [(0,1,23),(1,0,15),(1,2,45)]
sink = n-1
+def distance(d1,d2):
+ return mt.sqrt(sum([(d1[t]-d2[t])**2 for t in d1]))
+
def genereGraph():
test = False
G.add_edge(io,ie,weight=dist)
G.add_edge(ie,io,weight=dist)
test = not(any([ not(nx.has_path(G,o,sink)) for o in G.nodes() if sink in G.nodes() and o != sink]))
- return G
+ return (G,l)
+
+
+def afficheGraph(G,l,tx,ty,sink):
+ r = 20
+ img = cv.CreateImage ((tx, ty), 32, 3)
+ cv.Rectangle(img, (0,0),(tx,ty), cv.Scalar(255,255,255), thickness=-1)
+ def px((x,y)):
+ return(int(tx*x/coteCarre),ty-int(ty*y/coteCarre))
+ for i in set(range(len(l)))-set([sink]):
+ (x,y) = l[i]
+ pix,piy = px((x,y))
+ demx = distanceEmmissionMax*tx/coteCarre
+ cv.Circle(img, (pix,piy),demx, cv.Scalar(125,125,125))
+
+ for i in set(range(len(l)))-set([sink]):
+ (x,y) = l[i]
+ pix,piy = px((x,y))
+ cv.Circle(img, (pix,piy),r, cv.Scalar(125,125,125),thickness=-1)
+
+ #sink
+ (x,y) = l[sink]
+ pix,piy = px((x,y))
+
+ cv.Rectangle(img, (pix-r/2,piy-r/2),(pix+r/2,piy+r/2), cv.Scalar(125,125,125), thickness=-1)
+
+ for i in range(len(l)):
+ for j in range(len(l)):
+
+ if np.linalg.norm(np.array(l[i])-np.array(l[j])) < distanceEmmissionMax :
+ (xi,yi) = l[i]
+ pixi,piyi = px((xi,yi))
+ (xj,yj) = l[j]
+ pixj,piyj = px((xj,yj))
+ cv.Line(img, (pixi,piyi), (pixj,piyj), cv.Scalar(125,125,125))
+
+
+ """
+ for i in range(len(l)):
+ (x,y) = l[i]
+ pix,piy = px((x,y))
+ print i
+ textColor = (0, 0, 255) # red
+ font = cv2.FONT_HERSHEY_SIMPLEX
+ imgp =
+ cv2.putText(img, str(i), (pix-r/4,piy-r/2),font, 3.0, textColor)#,thickn """
+ cv.SaveImage("SensorNetwork.png",img)
G = nx.DiGraph()
G.add_weighted_edges_from(lg)
#nx.draw(G)
#pb.show()
+(G,l) = genereGraph()
+N = G.nodes()
+#V = list(set(sample(N,int(len(N)*vrate)))-set([sink]))
+V = list(set(N)-set([sink]))
+source = V
+print "source",source
+afficheGraph(G,l,500,500,sink)
+#nx.draw(G)
+#pb.show()
+
+
+
#print G.edges(data=True)
#TODO afficher le graphe et etre sur qu'il est connexe
-N = G.nodes()
-
-#V = list(set(sample(N,int(len(N)*vrate)))-set([sink]))
-V = list(set(N)-set([sink]))
-source = V
-print "source",source
-
L = range(len(G.edges()))
d = [di['weight'] for (_,_,di) in G.edges(data=True)]
-def distance(d1,d2):
- return mt.sqrt(sum([(d1[t]-d2[t])**2 for t in d1]))
def AfficheVariation (up,vp,lap,wp,thetap,etap,qp,Psp,Rhp,xp,valeurFonctionDualep):
def f_Ps(psh,h):
#print "ds f_ps",psh, v[h]* mt.log(float(sigma2)/D)/(gamma*((psh**2)**(float(2)/3))) +la[h]*psh
return v[h]* mt.log(float(sigma2)/D)/(gamma*mt.pow(float(2)/3)) +la[h]*psh
- for h in V:
+ for h in V:
if not ASYNC or random() < taux_succes:
"""
lah = 0.05 if la[h] == 0 else la[h]