improved structure, doc and naming
This commit is contained in:
29
graph.go
29
graph.go
@@ -261,55 +261,48 @@ func (g *Graph) ExportToArgo(id string) error {
|
||||
|
||||
fmt.Println(str)
|
||||
}
|
||||
|
||||
fmt.Println("Identified branches : ", list_branches)
|
||||
argo_builder := ArgoBuilder{*g,list_branches,nil}
|
||||
argo_builder := ArgoBuilder{graph : *g, branches: list_branches}
|
||||
argo_builder.CreateDAG()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Return a list containing the IDs of each link that make up a branch in the graph
|
||||
func (g *Graph) getListBranches(end_links map[string]models.Link, editable_link_list map[string]models.Link, current_branch []string) (list_branches [][]string) {
|
||||
func (g *Graph) getListBranches(end_links map[string]models.Link, unvisited_links_list map[string]models.Link, current_branch []string) (list_branches [][]string) {
|
||||
if current_branch == nil {
|
||||
current_branch = make([]string, 0)
|
||||
}
|
||||
|
||||
if editable_link_list == nil {
|
||||
editable_link_list = make(map[string]models.Link,len(g.Links))
|
||||
maps.Copy(editable_link_list,g.Links)
|
||||
fmt.Println(editable_link_list)
|
||||
if unvisited_links_list == nil {
|
||||
unvisited_links_list = make(map[string]models.Link,len(g.Links))
|
||||
maps.Copy(unvisited_links_list,g.Links)
|
||||
fmt.Println(unvisited_links_list)
|
||||
}
|
||||
|
||||
for link_id, _ := range end_links {
|
||||
// branch := []string{link_id}
|
||||
j := link_id
|
||||
new_branches := make([][]string,0)
|
||||
|
||||
|
||||
previous_index := g.hasPreviousLink(j, editable_link_list)
|
||||
previous_index := g.getPreviousLink(j, unvisited_links_list)
|
||||
if len(previous_index) == 0 {
|
||||
// new_branches = append(new_branches, []string{link_id})
|
||||
// return new_branches
|
||||
list_branches = append(list_branches, []string{link_id})
|
||||
}
|
||||
|
||||
for _, id_link := range previous_index {
|
||||
current_branch = append([]string{link_id},current_branch...)
|
||||
delete(editable_link_list, link_id)
|
||||
delete(unvisited_links_list, link_id)
|
||||
// create a new branch for each previous link, appending the current path to this node to the created branch
|
||||
new_end_link := make(map[string]models.Link,0)
|
||||
new_end_link[id_link] = g.Links[id_link]
|
||||
new_branches = g.getListBranches(new_end_link,editable_link_list,current_branch)
|
||||
new_branches = g.getListBranches(new_end_link,unvisited_links_list,current_branch)
|
||||
|
||||
for _, new_branch := range new_branches{
|
||||
current_branch = append(new_branch,link_id)
|
||||
list_branches = append(list_branches, current_branch)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
@@ -350,7 +343,7 @@ func (g *Graph) isSource(comp_id string,link_id string) bool {
|
||||
// with the same Destination id that the Source id in g.Links[linkIndex]
|
||||
// or nil if not
|
||||
|
||||
func (g *Graph) hasPreviousLink(link_id string,map_link map[string]models.Link) (previous_id []string) {
|
||||
func (g *Graph) getPreviousLink(link_id string,map_link map[string]models.Link) (previous_id []string) {
|
||||
for k, link := range map_link{
|
||||
if(k != link_id && link.Destination == g.Links[link_id].Source){
|
||||
previous_id = append(previous_id, k)
|
||||
|
||||
Reference in New Issue
Block a user