| """ |
| MPVR v1 - Multi-Path Vector Routing |
| Preuve de concept MTTV-flp |
| Simule Raft vs MPVR avec routage énergétique et mémoire (4e dimension) |
| """ |
| import random, itertools |
|
|
| def simulate(rounds=100, failure=50): |
| nodes=[0,1,2,3,4] |
| failed=1 |
| memory={n:1.2 for n in nodes} |
| results=[] |
| random.seed(101) |
| for r in range(1,rounds+1): |
| alive=[n for n in nodes if not (n==failed and r>=failure)] |
| followers=[n for n in [1,2,3,4] if n in alive] |
| costs={} |
| for i,j in itertools.combinations(nodes,2): |
| if i in alive and j in alive: |
| c=random.uniform(0.5,2.0) |
| costs[(i,j)]=costs[(j,i)]=c |
| def best(a,b): |
| best=costs.get((a,b),9) |
| for m in alive: |
| if m in (a,b): continue |
| c=costs.get((a,m),9)+costs.get((m,b),9) |
| if c<best: best=c |
| return best |
| raft=sum(costs.get((0,f),0) for f in followers)+sum(sorted(costs.get((f,0),0) for f in followers)[:3]) |
| cand=sorted([(best(0,t),t) for t in followers]) |
| v3=sum(c for c,_ in cand[:3]) |
| for t in followers: memory[t]=0.8*memory[t]+0.2*best(0,t) |
| avg=sum(memory[t] for t in followers)/len(followers) |
| quorum=2 if avg<1.25 else 3 |
| chosen=[] |
| for c,t in cand: |
| if c<=memory[t]*1.15: chosen.append((c,t)) |
| if len(chosen)>=quorum: break |
| if len(chosen)<quorum: chosen=cand[:quorum] |
| v4=sum(c for c,_ in chosen) |
| results.append((r,raft,v3,v4)) |
| return results |
|
|
| if __name__=="__main__": |
| for r,raft,v3,v4 in simulate()[:5]: |
| print(r, raft, v3, v4) |
|
|