Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate Tests for the Dominating Theta Path Algorithm #78

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 65 additions & 62 deletions include/Algorithms/PathFinding/DominatingThetaPath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,47 +200,48 @@ class DominatingThetaPath final {
std::vector<TEdgeId> edges;

Types::real result = \
labelSets_[target].for_all_optima(
labelSets_[target].template for_all_optima<ExecutionPolicy::sequential>(
[ this, &vertices, &edges, &isVertexInSubgraph, &isEdgeInSubgraph ]( TLabel const & optLabel )
{
Types::labelId labelId = optLabel.Index();
TVertexId vertexId = optLabel.Vertex();

do
{
TLabel const & label = LabelAt( vertexId, labelId );
labelId = label.Index();

ESSENTIAL_ASSERT ( graph_.VertexExists( vertexId ) );

if ( !isVertexInSubgraph[vertexId] )
{
isVertexInSubgraph[vertexId] = true;
vertices.push_back(vertexId);
}

if ( label.PreviousVertex() != Const::NONE )
{ // @todo multiple edges? It would be easier if the labels stored edges
Types::edgeId edge = graph_.EdgeId ( vertexId, label.PreviousVertex() );
if ( edge == Const::NONE )
{
edge = graph_.EdgeId ( label.PreviousVertex(), vertexId );
ESSENTIAL_ASSERT( edge != Const::NONE );
}
Types::labelId labelId = optLabel.Index();
TVertexId vertexId = optLabel.Vertex();

if (!isEdgeInSubgraph[edge])
do
{
isEdgeInSubgraph[edge] = true;
edges.push_back(edge);
}
TLabel const & label = LabelAt( vertexId, labelId );
labelId = label.Index();

ESSENTIAL_ASSERT ( graph_.VertexExists( vertexId ) );

if ( !isVertexInSubgraph[vertexId] )
{
isVertexInSubgraph[vertexId] = true;
vertices.push_back(vertexId);
}

if ( label.PreviousVertex() != Const::NONE )
{ // @todo multiple edges? It would be easier if the labels stored edges
Types::edgeId edge = graph_.EdgeId ( vertexId, label.PreviousVertex() );
if ( edge == Const::NONE )
{
edge = graph_.EdgeId ( label.PreviousVertex(), vertexId );
ESSENTIAL_ASSERT( edge != Const::NONE );
}

if (!isEdgeInSubgraph[edge])
{
isEdgeInSubgraph[edge] = true;
edges.push_back(edge);
}
}

vertexId = label.PreviousVertex();
labelId = label.PreviousLabel();

} while ( labelId != Const::NONE
&& vertexId != Const::NONE );
}

vertexId = label.PreviousVertex();
labelId = label.PreviousLabel();

} while ( labelId != Const::NONE
&& vertexId != Const::NONE );
});
);

resultSubgraph = Subgraph<TGraph const>(&graph_, vertices, edges);
return result;
Expand All @@ -264,7 +265,7 @@ class DominatingThetaPath final {

// Iterate over all optima
Types::real result = \
labelSets_[target].for_all_optima([ this, & parent = parent ]( TLabel const & optLabel )
labelSets_[target].template for_all_optima<ExecutionPolicy::sequential>([ this, & parent = parent ]( TLabel const & optLabel )
{
// Add a row for another label path from target t
parent.emplace_back( std::vector<TVertexId>() );
Expand Down Expand Up @@ -409,7 +410,7 @@ class DominatingThetaPath final {

numberOfPathsPerVertex.resize( graph_.NumberOfVertices(), 0 );

labelSets_[target].for_all_optima (
labelSets_[target].template for_all_optima<ExecutionPolicy::sequential> (
[&]( TLabel const & optLabel )
{
Types::labelId labelId = optLabel.Index();
Expand Down Expand Up @@ -476,38 +477,40 @@ class DominatingThetaPath final {
Types::count numberOfOptimalLabels = LabelSetAt(target).Optima().size(); // Divide by this value
Types::real weightOfPath = static_cast<Types::real>(1) / numberOfOptimalLabels;

labelSets_[target].template for_all_optima<ExecutionPolicy::sequential>( [&]( TLabel const & optLabel )
{
Types::labelId labelId = optLabel.Index();
TVertexId vertexId = target;
labelSets_[target].template for_all_optima<ExecutionPolicy::sequential>(
[&]( TLabel const & optLabel )
{
Types::labelId labelId = optLabel.Index();
TVertexId vertexId = target;

do {
TLabel & label = LabelAt( vertexId, labelId );
labelId = label.Index();
do {
TLabel & label = LabelAt( vertexId, labelId );
labelId = label.Index();

if ( ( label.PreviousLabel() == Const::NONE )
|| ( label.PreviousVertex() == Const::NONE )
|| ( vertexId == Const::NONE )
) break; // Label is already on path
if ( ( label.PreviousLabel() == Const::NONE )
|| ( label.PreviousVertex() == Const::NONE )
|| ( vertexId == Const::NONE )
) break; // Label is already on path

// Increase number of paths at "edgeId"
TEdgeId edgeId = ( graph_.EdgeId( label.PreviousVertex(), vertexId ) != Const::NONE )
? graph_.EdgeId( label.PreviousVertex(), vertexId )
: graph_.EdgeId( vertexId, label.PreviousVertex() );
// Increase number of paths at "edgeId"
TEdgeId edgeId = ( graph_.EdgeId( label.PreviousVertex(), vertexId ) != Const::NONE )
? graph_.EdgeId( label.PreviousVertex(), vertexId )
: graph_.EdgeId( vertexId, label.PreviousVertex() );

ESSENTIAL_ASSERT ( edgeId != Const::NONE );
ESSENTIAL_ASSERT ( edgeId != Const::NONE );

++numberOfPathsPerEdge[edgeId];
++numberOfPathsPerEdge[edgeId];

relativeNumberOfPathsPerEdge[edgeId] += weightOfPath;
relativeNumberOfPathsPerEdge[edgeId] += weightOfPath;

// Extract next label on the DTP
vertexId = label.PreviousVertex();
labelId = label.PreviousLabel();
// Extract next label on the DTP
vertexId = label.PreviousVertex();
labelId = label.PreviousLabel();

} while ( labelId != Const::NONE
&& vertexId != Const::NONE );
}); // For all labels in DTP at target vertex
} while ( labelId != Const::NONE
&& vertexId != Const::NONE );
}
); // For all labels in DTP at target vertex
}
///@}

Expand Down
18 changes: 11 additions & 7 deletions include/Auxiliary/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@
#include "Constants.hpp"
#include "Types.hpp"

// Linux operation systems such as Debian, Ubuntu, Gentoo, Fedora, openSUSE, RedHat, or Centos
// Linux operation systems such as Debian, Ubuntu, Gentoo, Fedora, openSUSE, RedHat, or Centos.
#if defined (__linux__)
#include <time.h>
#include <sys/time.h>
// Apple and iOS
#include <time.h>
#include <sys/time.h>
// Apple and iOS.
#elif defined(__APPLE__) && defined(__MACH__)
#include <mach/mach_time.h>
#include <mach/clock.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <mach/clock.h>
#include <mach/mach.h>
// Windows.
#elif defined (_WIN32) || defined (_WIN64)
#include <time.h>
#include <windows.h>
#endif

namespace egoa::Auxiliary {
Expand Down
4 changes: 2 additions & 2 deletions tests/Algorithms/PathFinding/TestDominatingThetaPath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class TestDTPPowerGridSpecific : public TestDominatingThetaPath {
TPowerGrid network_;
TPowerGrid const & constNetwork_ = network_;

Types::string const TestCaseAcm2018MtsfFigure4a_ = "../../framework/tests/Data/PowerGrids/ieee_2018_acm_eEnergy_MTSF_Figure4a.m";
Types::string const TestCaseAcm2018MtsfFigure4b_ = "../../framework/tests/Data/PowerGrids/ieee_2018_acm_eEnergy_MTSF_Figure4b.m";
Types::string const TestCaseAcm2018MtsfFigure4a_ = "../../tests/Data/PowerGrids/ieee_2018_acm_eEnergy_MTSF_Figure4a.m";
Types::string const TestCaseAcm2018MtsfFigure4b_ = "../../tests/Data/PowerGrids/ieee_2018_acm_eEnergy_MTSF_Figure4b.m";
Types::vertexId const source_ = 0;
TDtpTheta dtpTheta_;
};
Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ add_test(NAME TestBlockCutTree COMMAND TestBlockCutTree)
####################################################################################
# Tests for PATH FINDING ALGORITHMS ################################################
####################################################################################
# add_executable(TestDominatingThetaPath Algorithms/PathFinding/TestDominatingThetaPath.cpp)
# target_link_libraries(TestDominatingThetaPath EGOA gtest gtest_main gmock_main)
# add_test(NAME TestDominatingThetaPath COMMAND TestDominatingThetaPath)
add_executable(TestDominatingThetaPath Algorithms/PathFinding/TestDominatingThetaPath.cpp)
target_link_libraries(TestDominatingThetaPath EGOA gtest gtest_main gmock_main)
add_test(NAME TestDominatingThetaPath COMMAND TestDominatingThetaPath)

# add_executable(TestBetweennessCentrality Algorithms/Centralities/TestBetweennessCentrality.cpp)
# target_link_libraries(TestBetweennessCentrality EGOA gtest gtest_main gmock_main)
Expand Down
Loading