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

Added input/output variable attribute to global Minsky schema to supp… #424

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions schema/schema3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ namespace schema3

return false;
});

// add any I/O variables
vector<int> inVars, outVars;
for (auto& i: g.inVariables)
inVars.push_back(itemMap[i.get()]);
for (auto& i: g.outVariables)
outVars.push_back(itemMap[i.get()]);
inVariables=inVars;
outVariables=outVars;

// search for and link up integrals to their variables, and Godley table ports
g.recursiveDo(&minsky::GroupItems::items,[&](const minsky::Items&,minsky::Items::const_iterator i) {
Expand Down Expand Up @@ -630,6 +639,14 @@ namespace schema3
if (newItem->variableCast())
schema3VarMap[i.id]=i;
}

if (inVariables)
for (auto i: *inVariables)
g.inVariables.push_back(itemMap[i]);
if (outVariables)
for (auto i: *outVariables)
g.outVariables.push_back(itemMap[i]);

// second loop over items to wire up integrals, and populate Godley table variables
for (const auto& i: items)
{
Expand Down
1 change: 1 addition & 0 deletions schema/schema3.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ namespace schema3
std::string minskyVersion="unknown";
vector<Wire> wires;
vector<Item> items;
Optional<vector<int>> inVariables, outVariables;
vector<Group> groups;
vector<LockGroup> lockGroups;
minsky::Simulation rungeKutta;
Expand Down
21 changes: 20 additions & 1 deletion test/testModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,25 @@ SUITE(GodleyTableWindow)

}


TEST_FIXTURE(TestFixture, saveAsGroup)
{
group0->inVariables.push_back(a);
group0->makeSubroutine();
save("foo.mky");
CHECK(group0->inVariables.size());
CHECK(group0->outVariables.size());
saveGroupAsFile(*group0,"group0.mky");
insertGroupFromFile("group0.mky");
Group& newGroup=dynamic_cast<Group&>(*canvas.itemFocus);
// check I/O variables
CHECK_EQUAL(group0->inVariables.size(),newGroup.inVariables.size());
CHECK_EQUAL(group0->outVariables.size(),newGroup.outVariables.size());
for (int i=0; i<group0->inVariables.size(); ++i)
CHECK_EQUAL(group0->inVariables[i]->name(), newGroup.inVariables[i]->name());
for (int i=0; i<group0->outVariables.size(); ++i)
CHECK_EQUAL(group0->outVariables[i]->name(), newGroup.outVariables[i]->name());
// check items
CHECK_EQUAL(group0->items.size(), newGroup.items.size());
}

}
Loading