Skip to content

Commit

Permalink
fix: search by template in generated struct only
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil committed Nov 19, 2024
1 parent a160515 commit 3e3a51c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
41 changes: 10 additions & 31 deletions problem-solver/cxx/searchModule/agents/FindSolvingMethodAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,16 @@ ScResult FindSolvingMethodAgent::DoProgram(ScActionInitiatedEvent const & event,
generatedStruct << templateResult[i];
}
ScTemplateSearchResult searchResult;

if (m_context.SearchByTemplate(targetSituationTemplate, searchResult) &&
isGeneratedStructureFound(generatedStruct, searchResult))
bool isGeneratedConstructionFound = false;
m_context.SearchByTemplate(
targetSituationTemplate,
[&isGeneratedConstructionFound](ScTemplateSearchResultItem const & item) -> void {
isGeneratedConstructionFound = true;
},
[this, generatedStruct](ScAddr const & elementAddr) -> bool {
return m_context.CheckConnector(generatedStruct, elementAddr, ScType::EdgeAccessConstPosPerm);
});
if (isGeneratedConstructionFound)
{
suitableMethods.insert(solvingMethod);
break;
Expand Down Expand Up @@ -207,34 +214,6 @@ ScAddr FindSolvingMethodAgent::getSolvingMethodWorkingResultTemplate(ScAddr cons
throw std::runtime_error("Problem solving method has incorrect condition of use and result edge");
}

bool FindSolvingMethodAgent::isGeneratedStructureFound(
ScStructure const & generatedStruct,
ScTemplateSearchResult const & searchResult)
{
bool isFound;
for (size_t i = 0; i < searchResult.Size(); i++)
{
isFound = true;
ScTemplateResultItem resultItem;
searchResult.Get(i, resultItem);
for (size_t j = 0; j < resultItem.Size(); j++)
{
ScAddr el;
resultItem.Get(j, el);
if (!m_context.CheckConnector(generatedStruct, el, ScType::EdgeAccessConstPosPerm))
{
isFound = false;
break;
}
}
if (isFound)
{
break;
}
}
return isFound;
}

void FindSolvingMethodAgent::formResult(ScAction & action, ScAddrSet const & suitableMethods)
{
ScAddr resEdge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class FindSolvingMethodAgent : public ScActionInitiatedAgent
ScAddr getProblemActionNode(ScAddr const & problemStruct);
ScAddr getProblemConcept(ScAddr const & problemStruct);
ScAddr getSolvingMethodWorkingResultTemplate(ScAddr const & solvingMethod);
bool isGeneratedStructureFound(const ScStructure & generatedStruct, const ScTemplateSearchResult &);
void formResult(ScAction & action, ScAddrSet const & suitableMethods);
void removeGeneratedStructures(ScAddrSet const & structuresToRemove, ScAddrSet const & elementsToSave);
};
Expand Down

0 comments on commit 3e3a51c

Please sign in to comment.