add dist_noAC

This commit is contained in:
KusakabeSi 2022-05-13 16:10:06 +00:00
parent 919d13baa3
commit 7ec7ecde6b
5 changed files with 68 additions and 25 deletions

10
.vscode/launch.json vendored
View File

@ -33,6 +33,16 @@
"buildFlags": "-tags 'novpp'",
"env": {"CGO_CFLAGS":"-I/usr/include/memif"},
"args":["-config","example_config/p2p_mode/genp2p.yaml","-mode","gencfg","-cfgmode","p2p"/*,"-example"*/],
},
{
"name": "Launch Slove",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"buildFlags": "-tags 'novpp'",
"env": {"CGO_CFLAGS":"-I/usr/include/memif"},
"args":["-config","example_config/static_mode/path.txt","-mode","solve"],
}
]
}

View File

@ -174,7 +174,7 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
g.UpdateLatency(3, 5, 0.5, 99999, 0, false, false)
g.UpdateLatency(6, 4, 0.5, 99999, 0, false, false)
g.UpdateLatency(4, 6, 0.5, 99999, 0, false, false)
_, next, _ := g.FloydWarshall(false)
_, _, next, _ := g.FloydWarshall(false)
econfig.NextHopTable = next
} else {

View File

@ -154,7 +154,7 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
NMCfg.EdgeNode.MacPrefix = fmt.Sprintf("%02X:%02X:%02X:%02X", pbyte[0], pbyte[1], pbyte[2], pbyte[3])
}
dist, next, err := g.FloydWarshall(false)
dist, dist_noAC, next, err := g.FloydWarshall(false)
g.SetNHTable(next)
if err != nil {
fmt.Println("Error:", err)
@ -164,6 +164,7 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
fmt.Println(string(nhTableStr))
}
all_vert := g.Vertices()
fmt.Printf("Distance With Additional Cost\n")
if NMCfg.DistanceMatrix != "" {
for u := range all_vert {
for v := range all_vert {
@ -177,6 +178,20 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
}
}
}
fmt.Printf("Distance Without Additional Cost\n")
if NMCfg.DistanceMatrix != "" {
for u := range all_vert {
for v := range all_vert {
if u != v {
path, err := g.Path(u, v)
if err != nil {
return fmt.Errorf("couldn't find path from %v to %v: %v", u, v, err)
}
fmt.Printf("%d -> %d\t%3f\t%v\n", u, v, dist_noAC[u][v], path)
}
}
}
}
econfig, err := GetExampleEdgeConf(NMCfg.EdgeConfigTemplate, false)
if err != nil {
if enableP2P {

View File

@ -69,12 +69,13 @@ type HttpPeerLocalIP struct {
}
type HttpState struct {
PeerInfo map[mtypes.Vertex]HttpPeerInfo
Infinity float64
Edges map[mtypes.Vertex]map[mtypes.Vertex]float64
Edges_Nh map[mtypes.Vertex]map[mtypes.Vertex]float64
NhTable mtypes.NextHopTable
Dist mtypes.DistTable
PeerInfo map[mtypes.Vertex]HttpPeerInfo
Infinity float64
Edges map[mtypes.Vertex]map[mtypes.Vertex]float64
Edges_Nh map[mtypes.Vertex]map[mtypes.Vertex]float64
NhTable mtypes.NextHopTable
Dist mtypes.DistTable
Dist_noAC mtypes.DistTable
}
type HttpPeerInfo struct {
@ -563,12 +564,13 @@ func manage_get_peerstate(w http.ResponseWriter, r *http.Request) {
defer httpobj.RUnlock()
if time.Now().After(httpobj.http_StateExpire) {
hs := HttpState{
PeerInfo: make(map[mtypes.Vertex]HttpPeerInfo),
NhTable: httpobj.http_graph.GetNHTable(false),
Infinity: mtypes.Infinity,
Edges: httpobj.http_graph.GetEdges(false, false),
Edges_Nh: httpobj.http_graph.GetEdges(true, true),
Dist: httpobj.http_graph.GetDtst(),
PeerInfo: make(map[mtypes.Vertex]HttpPeerInfo),
NhTable: httpobj.http_graph.GetNHTable(false),
Infinity: mtypes.Infinity,
Edges: httpobj.http_graph.GetEdges(false, false),
Edges_Nh: httpobj.http_graph.GetEdges(true, true),
Dist: httpobj.http_graph.GetDtst(true),
Dist_noAC: httpobj.http_graph.GetDtst(false),
}
for _, peerinfo := range httpobj.http_sconfig.Peers {

View File

@ -26,8 +26,9 @@ type Latency struct {
}
type Fullroute struct {
Next mtypes.NextHopTable `yaml:"NextHopTable"`
Dist mtypes.DistTable `yaml:"DistanceTable"`
Next mtypes.NextHopTable `yaml:"NextHopTable"`
Dist mtypes.DistTable `yaml:"DistanceTable"`
Dist_noAC mtypes.DistTable `yaml:"DistanceTableWithoutAdditionalaCost"`
}
// IG is a graph of integers that satisfies the Graph interface.
@ -41,6 +42,7 @@ type IG struct {
TimeoutCheckInterval time.Duration
recalculateTime time.Time
dlTable mtypes.DistTable
dlTable_noAC mtypes.DistTable
nhTable mtypes.NextHopTable
changed bool
NhTableExpire time.Time
@ -133,7 +135,7 @@ func (g *IG) RecalculateNhTable(checkchange bool) (changed bool) {
return
}
dist, next, _ := g.FloydWarshall(false)
dist, dist_noAC, next, _ := g.FloydWarshall(false)
changed = false
if checkchange {
CheckLoop:
@ -147,7 +149,7 @@ func (g *IG) RecalculateNhTable(checkchange bool) (changed bool) {
}
}
}
g.dlTable, g.nhTable = dist, next
g.dlTable, g.dlTable_noAC, g.nhTable = dist, dist_noAC, next
g.recalculateTime = time.Now()
return
@ -349,7 +351,7 @@ func (g *IG) RemoveAllNegativeValue() {
}
}
func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, next mtypes.NextHopTable, err error) {
func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, dist_noAC mtypes.DistTable, next mtypes.NextHopTable, err error) {
if g.loglevel.LogInternal {
if !again {
fmt.Println("Internal: Start Floyd Warshall algorithm")
@ -360,20 +362,25 @@ func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, next mtypes.NextH
}
vert := g.Vertices()
dist = make(mtypes.DistTable)
dist_noAC = make(mtypes.DistTable)
next = make(mtypes.NextHopTable)
for u := range vert {
dist[u] = make(map[mtypes.Vertex]float64)
dist_noAC[u] = make(map[mtypes.Vertex]float64)
next[u] = make(map[mtypes.Vertex]mtypes.Vertex)
for v := range vert {
dist[u][v] = mtypes.Infinity
dist_noAC[u][v] = mtypes.Infinity
}
dist[u][u] = 0
dist_noAC[u][u] = 0
for _, v := range g.Neighbors(u) {
w := g.Weight(u, v, true)
wo := g.Weight(u, v, false)
if w < mtypes.Infinity {
v := v
dist[u][v] = w
dist_noAC[u][v] = wo
next[u][v] = v
}
g.SetOldWeight(u, v, wo)
@ -385,6 +392,7 @@ func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, next mtypes.NextH
if dist[i][k] < mtypes.Infinity && dist[k][j] < mtypes.Infinity {
if dist[i][j] > dist[i][k]+dist[k][j] {
dist[i][j] = dist[i][k] + dist[k][j]
dist_noAC[i][j] = dist_noAC[i][k] + dist_noAC[k][j]
next[i][j] = next[i][k]
}
}
@ -399,10 +407,11 @@ func (g *IG) FloydWarshall(again bool) (dist mtypes.DistTable, next mtypes.NextH
}
g.RemoveAllNegativeValue()
err = errors.New("negative cycle detected")
dist, next, _ = g.FloydWarshall(true)
dist, dist_noAC, next, _ = g.FloydWarshall(true)
return
} else {
dist = make(mtypes.DistTable)
dist_noAC = make(mtypes.DistTable)
next = make(mtypes.NextHopTable)
err = errors.New("negative cycle detected again")
if g.loglevel.LogInternal {
@ -452,8 +461,13 @@ func (g *IG) GetNHTable(recalculate bool) mtypes.NextHopTable {
return g.nhTable
}
func (g *IG) GetDtst() mtypes.DistTable {
return g.dlTable
func (g *IG) GetDtst(withAC bool) mtypes.DistTable {
if withAC {
return g.dlTable
} else {
return g.dlTable_noAC
}
}
func (g *IG) GetEdges(isOld bool, withAC bool) (edges map[mtypes.Vertex]map[mtypes.Vertex]float64) {
@ -560,14 +574,16 @@ func Solve(filePath string, pe bool) error {
input := string(inputb)
all_edge, _ := ParseDistanceMatrix(input)
g.UpdateLatencyMulti(all_edge, false, false)
dist, next, err := g.FloydWarshall(false)
dist, dist_noAC, next, err := g.FloydWarshall(false)
if err != nil {
fmt.Println("Error:", err)
}
g.dlTable, g.dlTable_noAC, g.nhTable = dist, dist_noAC, next
rr, _ := yaml.Marshal(Fullroute{
Dist: dist,
Next: next,
Dist: dist,
Dist_noAC: dist_noAC,
Next: next,
})
fmt.Print(string(rr))