Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixGraph
Commits
c88f6827
Commit
c88f6827
authored
Aug 26, 2020
by
Pierre Aubert
Browse files
Add method to remove Node and clear graph
parent
dd08346c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
206 additions
and
7 deletions
+206
-7
CMakeLists.txt
CMakeLists.txt
+1
-1
TESTS/CMakeLists.txt
TESTS/CMakeLists.txt
+1
-1
TESTS/TEST_DOT/CMakeLists.txt
TESTS/TEST_DOT/CMakeLists.txt
+1
-0
TESTS/TEST_DOT_LOOP/CMakeLists.txt
TESTS/TEST_DOT_LOOP/CMakeLists.txt
+1
-0
TESTS/TEST_DOT_REMOVE/CMakeLists.txt
TESTS/TEST_DOT_REMOVE/CMakeLists.txt
+9
-0
TESTS/TEST_DOT_REMOVE/main.cpp
TESTS/TEST_DOT_REMOVE/main.cpp
+42
-0
TESTS/TEST_DOT_TOTAL_LOOP/CMakeLists.txt
TESTS/TEST_DOT_TOTAL_LOOP/CMakeLists.txt
+1
-0
src/CMakeLists.txt
src/CMakeLists.txt
+5
-0
src/Graph.h
src/Graph.h
+8
-0
src/Graph_impl.h
src/Graph_impl.h
+72
-0
src/Node.h
src/Node.h
+4
-5
src/Node_impl.h
src/Node_impl.h
+16
-0
src/list_index_utils.cpp
src/list_index_utils.cpp
+26
-0
src/list_index_utils.h
src/list_index_utils.h
+19
-0
No files found.
CMakeLists.txt
View file @
c88f6827
...
...
@@ -11,7 +11,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
include_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
)
phoenix_create_find
_header
(
P
hoenix
G
raph Graph.h
""
)
phoenix_create_find
(
PhoenixGraph p
hoenix
_g
raph Graph.h
""
)
add_subdirectory
(
src
)
...
...
TESTS/CMakeLists.txt
View file @
c88f6827
...
...
@@ -6,5 +6,5 @@ add_definitions(-DCMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}")
add_subdirectory
(
TEST_DOT
)
add_subdirectory
(
TEST_DOT_LOOP
)
add_subdirectory
(
TEST_DOT_TOTAL_LOOP
)
add_subdirectory
(
TEST_DOT_REMOVE
)
TESTS/TEST_DOT/CMakeLists.txt
View file @
c88f6827
...
...
@@ -2,6 +2,7 @@ project(Phoenix)
add_executable
(
test_graph_to_dot main.cpp
)
target_link_libraries
(
test_graph_to_dot phoenix_graph
)
add_test
(
NAME TestGraphToDot
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_graph_to_dot
)
...
...
TESTS/TEST_DOT_LOOP/CMakeLists.txt
View file @
c88f6827
...
...
@@ -2,6 +2,7 @@ project(Phoenix)
add_executable
(
test_graph_to_dot_loop main.cpp
)
target_link_libraries
(
test_graph_to_dot_loop phoenix_graph
)
add_test
(
NAME TestGraphToDotLoop
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_graph_to_dot_loop
)
...
...
TESTS/TEST_DOT_REMOVE/CMakeLists.txt
0 → 100644
View file @
c88f6827
project
(
Phoenix
)
add_executable
(
test_graph_to_dot_remove main.cpp
)
target_link_libraries
(
test_graph_to_dot_remove phoenix_graph
)
add_test
(
NAME TestGraphToDotRemove
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_graph_to_dot_remove
)
TESTS/TEST_DOT_REMOVE/main.cpp
0 → 100644
View file @
c88f6827
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "Graph.h"
///Test the graph conversion to dot
void
testGraphToDot
(){
Graph
<
bool
>
graph
;
long
nodeA
=
graph
.
createNode
(
true
,
"a"
);
long
nodeB
=
graph
.
createNode
(
true
,
"b"
);
long
nodeC
=
graph
.
createNode
(
true
,
"c"
);
long
nodeD
=
graph
.
createNode
(
true
,
"d"
);
long
nodeE
=
graph
.
createNode
(
true
,
"e"
);
long
nodeRemove
=
graph
.
createNode
(
true
,
"to be removed"
);
graph
.
connectNode
(
nodeA
,
nodeC
);
graph
.
connectNode
(
nodeB
,
nodeC
);
graph
.
connectNode
(
nodeC
,
nodeE
);
graph
.
connectNode
(
nodeD
,
nodeE
);
graph
.
connectNode
(
nodeB
,
nodeRemove
);
graph
.
connectNode
(
nodeRemove
,
nodeE
);
graph
.
savePng
(
"testGraphBase.png"
);
graph
.
removeNode
(
nodeRemove
);
graph
.
savePng
(
"testGraphRemove.png"
);
}
int
main
(
int
argc
,
char
**
argv
){
testGraphToDot
();
return
0
;
}
TESTS/TEST_DOT_TOTAL_LOOP/CMakeLists.txt
View file @
c88f6827
...
...
@@ -2,6 +2,7 @@ project(Phoenix)
add_executable
(
test_graph_to_dot_total_loop main.cpp
)
target_link_libraries
(
test_graph_to_dot_total_loop phoenix_graph
)
add_test
(
NAME TestGraphToDotTotalLoop
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_graph_to_dot_total_loop
)
...
...
src/CMakeLists.txt
View file @
c88f6827
project
(
Phoenix
)
cmake_minimum_required
(
VERSION 3.0
)
file
(
GLOB phoenix_graph_SRC
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/*.cpp"
)
add_library
(
phoenix_graph SHARED
${
phoenix_graph_SRC
}
)
install
(
TARGETS phoenix_graph LIBRARY DESTINATION
${
LIBRARY_DIRECTORY
}
ARCHIVE DESTINATION
${
LIBRARY_DIRECTORY
}
)
file
(
GLOB headers
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/*.h"
)
install
(
FILES
${
headers
}
DESTINATION include/PhoenixGraph
)
src/Graph.h
View file @
c88f6827
...
...
@@ -29,6 +29,14 @@ class Graph{
Node
<
T
>
*
createNodePtr
(
const
T
&
data
,
const
std
::
string
&
name
=
""
);
void
clearIsUpdated
();
void
clearMapNode
();
void
clearFirstNode
();
void
clearLastNode
();
void
clearAll
();
void
removeNode
(
long
index
);
void
updateFirstLastNode
();
void
connectNode
(
long
parent
,
long
child
);
void
connectNode
(
long
parent
,
const
ListIndex
&
listChildren
);
...
...
src/Graph_impl.h
View file @
c88f6827
...
...
@@ -150,6 +150,78 @@ void Graph<T>::clearIsUpdated(){
}
}
///Clear the map of Node
template
<
typename
T
>
void
Graph
<
T
>::
clearMapNode
(){
p_mapNode
.
clear
();}
///Clear the list of first Node
template
<
typename
T
>
void
Graph
<
T
>::
clearFirstNode
(){
p_listFirstNode
.
clear
();}
///Clear the list of last Node
template
<
typename
T
>
void
Graph
<
T
>::
clearLastNode
(){
p_listLastNode
.
clear
();}
//Clear all Node
template
<
typename
T
>
void
Graph
<
T
>::
clearAll
(){
clearFirstNode
();
clearLastNode
();
clearMapNode
();
}
///Remove a Node from the Graph
/** @param index : index of the Node to be removed
*/
template
<
typename
T
>
void
Graph
<
T
>::
removeNode
(
long
index
){
Node
<
T
>
*
indexNode
=
getNode
(
index
);
if
(
indexNode
==
NULL
){
return
;}
//If the Node does not exist, we stop
//Get the parents of the current Node
ListIndex
&
listParent
=
indexNode
->
getListParent
();
if
(
listParent
.
size
()
!=
0lu
){
//Tell them they do not have child anymore
for
(
ListIndex
::
iterator
it
(
listParent
.
begin
());
it
!=
listParent
.
end
();
++
it
){
Node
<
T
>
*
parentNode
=
getNode
(
*
it
);
if
(
parentNode
==
NULL
){
continue
;}
parentNode
->
removeChild
(
index
);
}
}
else
{
//Let's remove the current Node from first Node
listindex_remove
(
p_listFirstNode
,
index
);
}
//Get the children of the current Node
ListIndex
&
listChild
=
indexNode
->
getListChild
();
if
(
listChild
.
size
()
!=
0lu
){
//Tell them they do not have parent anymore
for
(
ListIndex
::
iterator
it
(
listChild
.
begin
());
it
!=
listChild
.
end
();
++
it
){
Node
<
T
>
*
childNode
=
getNode
(
*
it
);
if
(
childNode
==
NULL
){
continue
;}
childNode
->
removeParent
(
index
);
}
}
else
{
//Let's remove the current Node from last Node
listindex_remove
(
p_listLastNode
,
index
);
}
//Now, let's remove the current Node
p_mapNode
.
erase
(
index
);
}
///Update the first and last Node of the Graph
template
<
typename
T
>
void
Graph
<
T
>::
updateFirstLastNode
(){
clearFirstNode
();
clearLastNode
();
for
(
typename
std
::
map
<
long
,
Node
<
T
>
>::
iterator
itNode
(
p_mapNode
.
begin
());
itNode
!=
p_mapNode
.
end
();
++
itNode
){
if
(
itNode
->
second
.
isStart
()){
//If the Node does not have any parent, it is a first Node
p_listFirstNode
.
push_back
(
itNode
->
first
);
}
if
(
itNode
->
second
.
isEnd
()){
//If the Node does not have any child, it is a last Node
p_listLastNode
.
push_back
(
itNode
->
first
);
}
}
}
///Connect a parent to its child
/** @param parent : index of the parent Node
* @param child : index of the child Node
...
...
src/Node.h
View file @
c88f6827
...
...
@@ -7,11 +7,7 @@
#ifndef __NODE_H__
#define __NODE_H__
#include <string>
#include <list>
///List of index to be used in the graph
typedef
std
::
list
<
long
>
ListIndex
;
#include "list_index_utils.h"
///@brief Node of a Graph
template
<
typename
T
>
...
...
@@ -26,6 +22,9 @@ class Node{
void
addChild
(
long
child
);
void
addParent
(
long
parent
);
void
removeChild
(
long
child
);
void
removeParent
(
long
parent
);
void
setListChild
(
const
ListIndex
&
listChild
);
void
setListParent
(
const
ListIndex
&
listParent
);
void
setIndex
(
long
index
);
...
...
src/Node_impl.h
View file @
c88f6827
...
...
@@ -81,6 +81,22 @@ void Node<T>::addParent(long parent){
p_listParent
.
push_back
(
parent
);
}
///Remove connection with child
/** @param child : index of the child to be removed
*/
template
<
typename
T
>
void
Node
<
T
>::
removeChild
(
long
child
){
listindex_remove
(
p_listChild
,
child
);
}
///Remove connection with parent
/** @param parent : index of the parent to be removed
*/
template
<
typename
T
>
void
Node
<
T
>::
removeParent
(
long
parent
){
listindex_remove
(
p_listParent
,
parent
);
}
///Set the list of children of the Node
/** @param listChild : list of children of the Node
*/
...
...
src/list_index_utils.cpp
0 → 100644
View file @
c88f6827
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "list_index_utils.h"
///Remove index from listIndex
/** @param[out] listIndex : list of index to be modified
* @param index : index to be removed from list of index
*/
void
listindex_remove
(
ListIndex
&
listIndex
,
long
index
){
if
(
listIndex
.
size
()
==
0lu
){
return
;}
ListIndex
::
iterator
it
(
listIndex
.
begin
());
while
(
it
!=
listIndex
.
end
()){
if
(
*
it
==
index
){
it
=
listIndex
.
erase
(
it
);
}
else
{
++
it
;
}
}
}
src/list_index_utils.h
0 → 100644
View file @
c88f6827
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#ifndef __LIST_INDEX_UTILS_H__
#define __LIST_INDEX_UTILS_H__
#include <string>
#include <list>
///List of index to be used in the graph
typedef
std
::
list
<
long
>
ListIndex
;
void
listindex_remove
(
ListIndex
&
listIndex
,
long
index
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment