Commit 1b61f18c authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: WIP: updated Overlord and all Tests to new Blueprint API

parent 3b2ddc64
......@@ -21,10 +21,13 @@ public:
typedef std::string ParameterKeyType;
typedef std::vector< std::string > ParameterValueType;
typedef std::map< ParameterKeyType, ParameterValueType > ParameterMapType;
// Component parameter map that sits on a node in the graph
typedef std::string ComponentNameType;
// Component parameter map that sits on a node in the graph
// and holds component configuration settings
struct ComponentPropertyType {
ComponentNameType name;
ParameterMapType parameterMap;
};
......@@ -39,10 +42,13 @@ public:
boost::vecS,
boost::directedS,
ComponentPropertyType,
ConnectionPropertyType >,
std::string > GraphType;
ConnectionPropertyType
>,
ComponentNameType > GraphType;
typedef GraphType::label_type ComponentNameType;
//typedef GraphType::label_type ComponentNameType;
typedef std::vector<ComponentNameType> ComponentNamesType;
typedef boost::graph_traits< GraphType >::vertex_descriptor ComponentIndexType;
typedef boost::graph_traits< GraphType >::vertex_iterator ComponentIteratorType;
typedef std::pair< ComponentIteratorType, ComponentIteratorType > ComponentIteratorPairType;
......@@ -70,6 +76,8 @@ public:
// interface procedurally.
// void DeleteComponent( ComponentIndexType );
ComponentNamesType GetComponentNames(void);
ComponentIteratorPairType GetComponentIterator( void ) {
return boost::vertices( this->m_Graph );
}
......@@ -85,15 +93,15 @@ public:
bool ConnectionExists(ComponentNameType upstream, ComponentNameType downstream);
// Returns iterator for all connections in the graph
ConnectionIteratorPairType GetConnectionIterator( void ) {
return boost::edges(this->m_Graph);
}
ConnectionIteratorPairType GetConnectionIterator(void);
// Returns the outgoing connections from a component in the graph,
// i.e. all components that reads data from given component
OutputIteratorPairType GetOutputIterator( const ComponentNameType name ) {
return boost::out_edges(this->m_Graph.vertex(name), this->m_Graph.graph());
}
OutputIteratorPairType GetOutputIterator(const ComponentNameType name);
// Returns a vector of the Component names at the outgoing direction
// TODO: should this be an iterator over the names?
ComponentNamesType GetOutputNames(const ComponentNameType name);
void WriteBlueprint( const std::string filename );
......
......@@ -45,7 +45,7 @@ Blueprint
::AddComponent(ComponentNameType name)
{
this->Modified();
ComponentIndexType index = this->m_Graph.add_vertex(name);
ComponentIndexType index = this->m_Graph.add_vertex(name, { name, { {} } });
// Return component index so component can retrieved at a later time
return index;
......@@ -56,7 +56,7 @@ Blueprint
::AddComponent(ComponentNameType name, ParameterMapType parameterMap)
{
this->Modified();
ComponentIndexType index = this->m_Graph.add_vertex(name, { parameterMap });
ComponentIndexType index = this->m_Graph.add_vertex(name, { name, parameterMap });
// Return component index so component can retrieved at a later time
return index;
......@@ -89,6 +89,14 @@ Blueprint
// remove_vertex( index, this->m_Graph );
// }
Blueprint::ComponentNamesType Blueprint::GetComponentNames(void){
ComponentNamesType container;
for (auto it = boost::vertices(this->m_Graph.graph()).first; it != boost::vertices(this->m_Graph.graph()).second; ++it){
container.push_back(this->m_Graph.graph()[*it].name);
}
return container;
}
bool
Blueprint
::AddConnection(ComponentNameType upstream, ComponentNameType downstream)
......@@ -163,6 +171,34 @@ Blueprint
return boost::edge_by_label( upstream, downstream, this->m_Graph).second;
}
Blueprint::ConnectionIteratorPairType
Blueprint
::GetConnectionIterator(void) {
return boost::edges(this->m_Graph);
}
Blueprint::OutputIteratorPairType
Blueprint
::GetOutputIterator(const ComponentNameType name) {
return boost::out_edges(this->m_Graph.vertex(name), this->m_Graph);
}
Blueprint::ComponentNamesType
Blueprint
::GetOutputNames(const ComponentNameType name) {
ComponentNamesType container;
OutputIteratorPairType outputIteratorPair = boost::out_edges(this->m_Graph.vertex(name), this->m_Graph);
for (auto it = outputIteratorPair.first; it != outputIteratorPair.second; ++it){
//boost::vertex()
//boost::edge_by_label(upstream, downstream, this->m_Graph).first
container.push_back(this->m_Graph.graph()[it->m_target].name);
}
return container;
}
Blueprint::ConnectionIndexType
Blueprint
::GetConnectionIndex( ComponentNameType upstream, ComponentNameType downstream )
......
......@@ -36,7 +36,7 @@ namespace selx
typedef ComponentBase ComponentType;
typedef ComponentSelector::Pointer ComponentSelectorPointer;
typedef std::vector<ComponentSelectorPointer> ComponentSelectorContainerType;
typedef std::map< Blueprint::ComponentNameType, ComponentSelectorPointer> ComponentSelectorContainerType;
typedef ComponentSelectorContainerType::iterator ComponentSelectorIteratorType;
typedef itk::ImageFileReader<itk::Image<float, 2>> Reader2floatType;
......
......@@ -94,12 +94,10 @@ namespace selx
bool Overlord::UpdateSelectors()
{
bool allUniqueComponents = true;
Blueprint::ComponentIteratorPairType componentItPair = this->m_Blueprint->GetComponentIterator();
Blueprint::ComponentIteratorPairType::first_type componentIt;
Blueprint::ComponentIteratorPairType::second_type componentItEnd = componentItPair.second;
for (componentIt = componentItPair.first; componentIt != componentItEnd; ++componentIt)
Blueprint::ComponentNamesType componentNames = this->m_Blueprint->GetComponentNames();
for (auto const & name : componentNames)
{
ComponentSelector::NumberOfComponentsType numberOfComponents = this->m_ComponentSelectorContainer[*componentIt]->UpdatePossibleComponents();
ComponentSelector::NumberOfComponentsType numberOfComponents = this->m_ComponentSelectorContainer[name]->UpdatePossibleComponents();
// The current idea of the configuration setup is that the number of
// possible components at a node can only be reduced by adding criteria.
......@@ -112,7 +110,7 @@ namespace selx
{
allUniqueComponents = false;
}
std::cout << "blueprint node " << *componentIt << " has selected " << numberOfComponents << " components" << std::endl;
std::cout << "blueprint node " << name << " has selected " << numberOfComponents << " components" << std::endl;
}
return allUniqueComponents;
......@@ -120,15 +118,14 @@ namespace selx
void Overlord::ApplyNodeConfiguration()
{
Blueprint::ComponentIteratorPairType componentItPair = this->m_Blueprint->GetComponentIterator();
Blueprint::ComponentIteratorPairType::first_type componentIt;
Blueprint::ComponentIteratorPairType::second_type componentItEnd = componentItPair.second;
for (componentIt = componentItPair.first; componentIt != componentItEnd; ++componentIt)
Blueprint::ComponentNamesType componentNames = this->m_Blueprint->GetComponentNames();
for (auto const & name : componentNames)
{
ComponentSelectorPointer currentComponentSelector = ComponentSelector::New();
Blueprint::ParameterMapType currentProperty = this->m_Blueprint->GetComponent(*componentIt);
Blueprint::ParameterMapType currentProperty = this->m_Blueprint->GetComponent(name);
currentComponentSelector->SetCriteria(currentProperty);
this->m_ComponentSelectorContainer.push_back(currentComponentSelector);
// insert new element
this->m_ComponentSelectorContainer[name]=currentComponentSelector;
}
return;
}
......@@ -162,30 +159,23 @@ namespace selx
//{
//}
Blueprint::ComponentIndexType index;
for (index = 0; index < this->m_ComponentSelectorContainer.size(); ++index)
Blueprint::ComponentNamesType componentNames = this->m_Blueprint->GetComponentNames();
for (auto const & name : componentNames)
{
Blueprint::OutputIteratorPairType ouputItPair = this->m_Blueprint->GetOutputIterator(index);
Blueprint::OutputIteratorPairType::first_type ouputIt;
Blueprint::OutputIteratorPairType::second_type ouputItEnd = ouputItPair.second;
for (ouputIt = ouputItPair.first; ouputIt != ouputItEnd; ++ouputIt)
for (auto const & outgoingName : this->m_Blueprint->GetOutputNames(name))
{
//TODO check direction upstream/downstream input/output source/target
Blueprint::ParameterMapType currentProperty = this->m_Blueprint->GetConnection(ouputIt->m_source, ouputIt->m_target);
for (Blueprint::ParameterMapType::const_iterator it = currentProperty.begin(); it != currentProperty.cend(); ++it)
Blueprint::ParameterMapType connectionProperties = this->m_Blueprint->GetConnection(name, outgoingName);
if (connectionProperties.count("NameOfInterface") > 0)
{
if (it->first == "NameOfInterface")
{
ComponentBase::CriteriaType additionalSourceCriteria;
additionalSourceCriteria.insert(ComponentBase::CriterionType("HasProvidingInterface", it->second));
ComponentBase::CriteriaType additionalSourceCriteria;
additionalSourceCriteria.insert(ComponentBase::CriterionType("HasProvidingInterface", connectionProperties["NameOfInterface"]));
ComponentBase::CriteriaType additionalTargetCriteria;
additionalTargetCriteria.insert(ComponentBase::CriterionType("HasAcceptingInterface", it->second));
ComponentBase::CriteriaType additionalTargetCriteria;
additionalTargetCriteria.insert(ComponentBase::CriterionType("HasAcceptingInterface", connectionProperties["NameOfInterface"]));
this->m_ComponentSelectorContainer[ouputIt->m_source]->AddCriteria(additionalSourceCriteria);
this->m_ComponentSelectorContainer[ouputIt->m_target]->AddCriteria(additionalTargetCriteria);
}
this->m_ComponentSelectorContainer[name]->AddCriteria(additionalSourceCriteria);
this->m_ComponentSelectorContainer[outgoingName]->AddCriteria(additionalTargetCriteria);
}
}
}
......@@ -194,29 +184,42 @@ namespace selx
}
bool Overlord::ConnectComponents()
{
bool isAllSuccess = true;
//TODO: redesign loops, see ApplyConnectionConfiguration()
Blueprint::ComponentIndexType index;
for (index = 0; index < this->m_ComponentSelectorContainer.size(); ++index)
Blueprint::ComponentNamesType componentNames = this->m_Blueprint->GetComponentNames();
for (auto const & name : componentNames)
{
Blueprint::OutputIteratorPairType ouputItPair = this->m_Blueprint->GetOutputIterator(index);
Blueprint::OutputIteratorPairType::first_type ouputIt;
Blueprint::OutputIteratorPairType::second_type ouputItEnd = ouputItPair.second;
for (ouputIt = ouputItPair.first; ouputIt != ouputItEnd; ++ouputIt)
for (auto const & outgoingName : this->m_Blueprint->GetOutputNames(name))
{
//TODO check direction upstream/downstream input/output source/target
//TODO GetComponent returns NULL if possible components !=1 we can check for that, but Overlord::UpdateSelectors() does something similar.
ComponentBase::Pointer sourceComponent = this->m_ComponentSelectorContainer[ouputIt->m_source]->GetComponent();
ComponentBase::Pointer targetComponent = this->m_ComponentSelectorContainer[ouputIt->m_target]->GetComponent();
int numberOfConnections = targetComponent->AcceptConnectionFrom(sourceComponent);
ComponentBase::Pointer sourceComponent = this->m_ComponentSelectorContainer[name]->GetComponent();
ComponentBase::Pointer targetComponent = this->m_ComponentSelectorContainer[outgoingName]->GetComponent();
Blueprint::ParameterMapType connectionProperties = this->m_Blueprint->GetConnection(name, outgoingName);
int numberOfConnections = 0;
if (connectionProperties.count("NameOfInterface") > 0)
{
// connect only via interfaces provided by user configuration
for (auto const & interfaceName : connectionProperties["NameOfInterface"])
{
numberOfConnections += targetComponent->AcceptConnectionFrom(interfaceName.c_str(), sourceComponent);
}
}
else
{
// connect via all possible interfaces
numberOfConnections = targetComponent->AcceptConnectionFrom(sourceComponent);
}
if (numberOfConnections == 0)
{
isAllSuccess = false;
std::cout << "Warning: a connection was specified, but no compatible interfaces were found.";
}
}
}
//TODO should we communicate by exceptions instead of returning booleans?
return true;
return isAllSuccess;
}
bool Overlord::ConnectSources()
{
......@@ -225,9 +228,9 @@ namespace selx
int readercounter = 0; // temporary solution for reader filenames
// TODO redesign ComponentBase class to accept a single criterion instead of a criteria mapping.
for (auto && componentSelector : (this->m_ComponentSelectorContainer))
for (const auto & componentSelector : (this->m_ComponentSelectorContainer))
{
ComponentBase::Pointer component = componentSelector->GetComponent();
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriteria({ { "HasProvidingInterface", { "SourceInterface" } } })) // TODO MeetsCriterion
{
......@@ -244,14 +247,12 @@ namespace selx
// For now, we just create the readers here.
Reader3doubleType::Pointer reader;
reader = Reader3doubleType::New();
//std::stringstream filename;
//filename << "C:\\wp\\SuperElastix\\bld2\\SuperElastix-build\\bin\\Debug\\sourceimage" << readercounter << ".mhd";
//filename << "source3dimage" << readercounter << ".mhd";
//reader->SetFileName(filename.str());
if (readercounter >= this->inputFileNames.size())
{
itkExceptionMacro("not enough inputFileNames provided")
}
reader->SetFileName(this->inputFileNames[readercounter]);
this->m_Readers3double->push_back(reader);
......@@ -265,14 +266,12 @@ namespace selx
// For now, we just create the readers here.
Reader2floatType::Pointer reader;
reader = Reader2floatType::New();
//std::stringstream filename;
//filename << "C:\\wp\\SuperElastix\\bld2\\SuperElastix-build\\bin\\Debug\\sourceimage" << readercounter << ".mhd";
//filename << "source2dimage" << readercounter << ".mhd";
//reader->SetFileName(filename.str());
if (readercounter >= this->inputFileNames.size())
{
itkExceptionMacro("not enough inputFileNames provided")
}
reader->SetFileName(this->inputFileNames[readercounter]);
this->m_Readers2float->push_back(reader);
......@@ -303,9 +302,9 @@ namespace selx
CriteriaType sinkCriteria;
sinkCriteria.insert(sinkCriterion);
for (auto && componentSelector : (this->m_ComponentSelectorContainer))
for (auto const & componentSelector : (this->m_ComponentSelectorContainer))
{
ComponentBase::Pointer component = componentSelector->GetComponent();
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriteria(sinkCriteria)) // TODO MeetsCriterion
{
SinkInterface* provingSinkInterface = dynamic_cast<SinkInterface*> (&(*component));
......@@ -325,6 +324,7 @@ namespace selx
{
itkExceptionMacro("not enough outputFileNames provided")
}
writer->SetFileName(this->outputFileNames[writercounter]);
this->m_WritersDisplacement3double->push_back(writer);
......@@ -340,6 +340,7 @@ namespace selx
{
itkExceptionMacro("not enough inputFileNames provided")
}
writer->SetFileName(this->outputFileNames[writercounter]);
this->m_WritersDisplacement2float->push_back(writer);
......@@ -350,13 +351,12 @@ namespace selx
// For now, we just create the writers here.
Writer3doubleType::Pointer writer;
writer = Writer3doubleType::New();
//std::stringstream filename;
//filename << "sink3dimage" << writercounter << ".mhd";
//writer->SetFileName(filename.str());
if (writercounter >= this->outputFileNames.size())
{
itkExceptionMacro("not enough outputFileNames provided")
}
writer->SetFileName(this->outputFileNames[writercounter]);
this->m_Writers3double->push_back(writer);
......@@ -368,9 +368,7 @@ namespace selx
// For now, we just create the writers here.
Writer2floatType::Pointer writer;
writer = Writer2floatType::New();
//std::stringstream filename;
//filename << "sink2dimage" << writercounter << ".mhd";
//writer->SetFileName(filename.str());
if (writercounter >= this->outputFileNames.size())
{
itkExceptionMacro("not enough outputFileNames provided")
......@@ -401,9 +399,9 @@ namespace selx
CriteriaType runRegistrationCriteria;
runRegistrationCriteria.insert(runRegistrationCriterion);
for (auto && componentSelector : (this->m_ComponentSelectorContainer))
for (auto const & componentSelector : (this->m_ComponentSelectorContainer))
{
ComponentBase::Pointer component = componentSelector->GetComponent();
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriteria(runRegistrationCriteria)) // TODO MeetsCriterion
{
this->m_RunRegistrationComponents->push_back(component);
......@@ -422,9 +420,9 @@ namespace selx
CriteriaType afterRegistrationCriteria;
afterRegistrationCriteria.insert(afterRegistrationCriterion);
for (auto && componentSelector : (this->m_ComponentSelectorContainer))
for (auto const & componentSelector : (this->m_ComponentSelectorContainer))
{
ComponentBase::Pointer component = componentSelector->GetComponent();
ComponentBase::Pointer component = componentSelector.second->GetComponent();
if (component->MeetsCriteria(afterRegistrationCriteria)) // TODO MeetsCriterion
{
this->m_AfterRegistrationComponents->push_back(component);
......
......@@ -13,7 +13,7 @@ public:
typedef Blueprint::ParameterValueType ParameterValueType;
virtual void SetUp() {
parameterMap["ComponentName"] = ParameterValueType(1, "TestName");
parameterMap["NameOfClass"] = ParameterValueType(1, "TestClassName");
}
ParameterMapType parameterMap;
......@@ -25,31 +25,31 @@ TEST_F( BlueprintTest, AddComponent )
EXPECT_NO_THROW( blueprint = Blueprint::New() );
ComponentIndexType index0;
EXPECT_NO_THROW( index0 = blueprint->AddComponent() );
EXPECT_NO_THROW( index0 = blueprint->AddComponent( "MyComponentName" ) );
ComponentIndexType index1;
EXPECT_NO_THROW( index1 = blueprint->AddComponent( parameterMap ) );
EXPECT_NO_THROW(index1 = blueprint->AddComponent("MyComponentName", parameterMap));
}
TEST_F( BlueprintTest, GetComponent )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index = blueprint->AddComponent( parameterMap );
ComponentIndexType index = blueprint->AddComponent("MyComponentName", parameterMap);
ParameterMapType parameterMapTest;
EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] );
EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( "MyComponentName" ) );
EXPECT_EQ( parameterMap["NameOfClass"], parameterMapTest["NameOfClass"] );
}
TEST_F( BlueprintTest, SetComponent )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index = blueprint->AddComponent( parameterMap );
ComponentIndexType index = blueprint->AddComponent( "MyComponentName", parameterMap);
ParameterMapType parameterMapTest;
EXPECT_NO_THROW( blueprint->SetComponent( index, parameterMap ) );
EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] );
EXPECT_NO_THROW(blueprint->SetComponent("MyComponentName", parameterMap));
EXPECT_NO_THROW(parameterMapTest = blueprint->GetComponent("MyComponentName"));
EXPECT_EQ( parameterMap["NameOfClass"], parameterMapTest["NameOfClass"] );
}
// TODO: The final line segfaults because GetComponent does not check that the index actually
......@@ -61,7 +61,7 @@ TEST_F( BlueprintTest, SetComponent )
//
// ParameterMapType parameterMapTest;
// EXPECT_NO_THROW( parameterMapTest = blueprint->GetComponent( index ) );
// EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest["ComponentName"] );
// EXPECT_EQ( parameterMap["NameOfClass"], parameterMapTest["NameOfClass"] );
//
// EXPECT_NO_THROW( blueprint->DeleteComponent( index ) );
// EXPECT_ANY_THROW( parameterMapTest = blueprint->GetComponent( index ) );
......@@ -71,85 +71,85 @@ TEST_F( BlueprintTest, AddConnection )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
ComponentIndexType index2 = blueprint->AddComponent();
ComponentIndexType index0 = blueprint->AddComponent( "Component0" );
ComponentIndexType index1 = blueprint->AddComponent( "Component1" );
ComponentIndexType index2 = blueprint->AddComponent( "Component2" );
// Connection should not exist
EXPECT_FALSE( blueprint->ConnectionExists( index0, index1 ) );
EXPECT_FALSE(blueprint->ConnectionExists("Component0", "Component1"));
// Connection should be added
EXPECT_TRUE( blueprint->AddConnection( index0, index1 ) );
EXPECT_TRUE(blueprint->AddConnection("Component0", "Component1"));
// Connection should exist
EXPECT_TRUE( blueprint->ConnectionExists( index0, index1 ) );
EXPECT_TRUE(blueprint->ConnectionExists("Component0", "Component1"));
// Another connection between same components should not be added
// (user should use SetComponent() instead)
EXPECT_FALSE( blueprint->AddConnection( index0, index1 ) );
EXPECT_FALSE(blueprint->AddConnection("Component0", "Component1"));
// Connection should be empty
ParameterMapType parameterMapTest0;
EXPECT_NO_THROW( parameterMapTest0 = blueprint->GetConnection( index0, index1 ) );
EXPECT_NO_THROW(parameterMapTest0 = blueprint->GetConnection("Component0", "Component1"));
EXPECT_EQ( 0u, parameterMapTest0.size() );
// Connection with properties should be added. Testing if properties was
// properly set requires a call to GetConnection() which is the responsibility
// of the next test.
ParameterMapType parameterMapTest1;
EXPECT_TRUE( blueprint->AddConnection( index1, index2, parameterMap ) );
EXPECT_TRUE(blueprint->AddConnection("Component1", "Component2", parameterMap));
}
TEST_F( BlueprintTest, GetConnection )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
ComponentIndexType index0 = blueprint->AddComponent("Component0");
ComponentIndexType index1 = blueprint->AddComponent("Component1");
ParameterMapType parameterMapTest0;
EXPECT_TRUE( blueprint->AddConnection( index0, index1, parameterMap ) );
EXPECT_NO_THROW( parameterMapTest0 = blueprint->GetConnection( index0, index1 ) );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest0["ComponentName"] );
EXPECT_TRUE(blueprint->AddConnection("Component0", "Component1", parameterMap));
EXPECT_NO_THROW(parameterMapTest0 = blueprint->GetConnection("Component0", "Component1"));
EXPECT_EQ( parameterMap["NameOfClass"], parameterMapTest0["NameOfClass"] );
}
TEST_F( BlueprintTest, SetConnection )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
blueprint->AddConnection( index0, index1, parameterMap );
ComponentIndexType index0 = blueprint->AddComponent("Component0");
ComponentIndexType index1 = blueprint->AddComponent("Component1");
blueprint->AddConnection("Component0", "Component1", parameterMap);
ParameterMapType parameterMapTest0;
parameterMapTest0 = blueprint->GetConnection( index0, index1 );
EXPECT_EQ( parameterMap["ComponentName"], parameterMapTest0["ComponentName"] );
parameterMapTest0 = blueprint->GetConnection("Component0", "Component1");
EXPECT_EQ( parameterMap["NameOfClass"], parameterMapTest0["NameOfClass"] );
ParameterMapType parameterMapTest1;
parameterMapTest1["ComponentName"] = ParameterValueType(1, "OtherName");
EXPECT_TRUE( blueprint->SetConnection( index0, index1, parameterMapTest1 ) );
parameterMapTest1["NameOfClass"] = ParameterValueType(1, "OtherName");
EXPECT_TRUE(blueprint->SetConnection("Component0", "Component1", parameterMapTest1));
ParameterMapType parameterMapTest2;
EXPECT_NO_THROW( parameterMapTest2 = blueprint->GetConnection( index0, index1 ) );
EXPECT_EQ( parameterMapTest1["ComponentName"], parameterMapTest2["ComponentName"] );
EXPECT_NO_THROW(parameterMapTest2 = blueprint->GetConnection("Component0", "Component1"));
EXPECT_EQ( parameterMapTest1["NameOfClass"], parameterMapTest2["NameOfClass"] );
}
TEST_F( BlueprintTest, DeleteConnection )
{
BlueprintPointerType blueprint = Blueprint::New();
ComponentIndexType index0 = blueprint->AddComponent();
ComponentIndexType index1 = blueprint->AddComponent();
blueprint->AddConnection( index0, index1 );
ComponentIndexType index0 = blueprint->AddComponent("Component0");
ComponentIndexType index1 = blueprint->AddComponent("Component1");
blueprint->AddConnection("Component0", "Component1");
// Connection should exist
EXPECT_TRUE( blueprint->ConnectionExists( index0, index1 ) );
EXPECT_TRUE(blueprint->ConnectionExists("Component0", "Component1"));
// Connection be deleted
EXPECT_TRUE( blueprint->DeleteConnection( index0, index1 ) );
EXPECT_TRUE(blueprint->DeleteConnection("Component0", "Component1"));
// Connection should not exist
EXPECT_FALSE( blueprint->ConnectionExists( index0, index1 ) );
EXPECT_FALSE(blueprint->ConnectionExists("Component0", "Component1"));
}
TEST_F( BlueprintTest, WriteBlueprint )
......@@ -161,31 +161,36 @@ TEST_F( BlueprintTest, WriteBlueprint )
component0Parameters["NameOfClass"] = { "MyMetric" };
component0Parameters["Dimensionality"] = { "3" };
component0Parameters["Kernel"] = { "5", "5", "5" };
ComponentIndexType index0 = blueprint->AddComponent(component0Parameters);
ComponentIndexType index0 = blueprint->AddComponent("Metric", component0Parameters);
ParameterMapType component1Parameters;
component1Parameters["NameOfClass"] = { "MyFiniteDifferenceCalculator" };
component1Parameters["Delta"] = { "0.01" };
ComponentIndexType index1 = blueprint->AddComponent(component1Parameters);
ComponentIndexType index1 = blueprint->AddComponent("MetricGradient", component1Parameters);
ParameterMapType component2Parameters;
component2Parameters["NameOfClass"] = { "MyOptimizer" };