1 Star 5 Fork 0

Thoughtworks/tequila

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dot.go 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
newlee 提交于 2017-11-11 23:43 +08:00 . refactor for solution model
package main
import (
"github.com/awalterschulze/gographviz"
. "github.com/newlee/tequila/model"
"io/ioutil"
//"fmt"
)
func edgesKey(edges map[string][]*gographviz.Edge) []string {
result := make([]string, 0)
for key := range edges {
result = append(result, key)
}
return result
}
func ParseProblemModel(dotFile string) *ProblemModel {
fbuf, _ := ioutil.ReadFile(dotFile)
g, _ := gographviz.Read(fbuf)
c2pMap := make(map[string]string)
p2c := g.Relations.ParentToChildren
subDomains := make(map[string]*SubDomain)
if _, ok := p2c["g"]; ok {
for key := range p2c["g"] {
c2pMap[key] = "subdomain"
}
subDomains["subdomain"] = NewSubDomain()
} else {
for clusterKey := range p2c {
subDomainName := g.SubGraphs.SubGraphs[clusterKey].Attrs["label"]
for key := range p2c[clusterKey] {
c2pMap[key] = subDomainName
}
subDomains[subDomainName] = NewSubDomain()
}
}
cms := InitCommentMapping()
for _, node := range g.Nodes.Nodes {
subDomain := subDomains[c2pMap[node.Name]]
subDomain.AddNode(cms, node.Name, node.Attrs["comment"])
}
for key := range g.Edges.SrcToDsts {
edgeKeys := edgesKey(g.Edges.SrcToDsts[key])
subDomain := subDomains[c2pMap[key]]
subDomain.AddRelations(key, edgeKeys)
}
return &ProblemModel{SubDomains: subDomains}
}
func ParseSolutionModel(dotFile string) *BCModel {
fbuf, _ := ioutil.ReadFile(dotFile)
g, _ := gographviz.Read(fbuf)
p2c := g.Relations.ParentToChildren
model := NewBCModel()
for clusterKey := range p2c {
if clusterKey != "g" {
layerName := g.SubGraphs.SubGraphs[clusterKey].Attrs["label"]
model.AppendLayer(layerName)
for key := range p2c[clusterKey] {
model.AppendNode(layerName, key)
}
}
}
for _, node := range g.Nodes.Nodes {
model.AddNode(node.Name, node.Attrs["comment"])
}
for key := range g.Edges.SrcToDsts {
edgeKeys := edgesKey(g.Edges.SrcToDsts[key])
model.AddRelations(key, edgeKeys)
}
return model
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/thoughtworks/tequila.git
git@gitee.com:thoughtworks/tequila.git
thoughtworks
tequila
tequila
master

搜索帮助