Skip to content

Commit

Permalink
Fix printing alg expr #232
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Apr 4, 2024
1 parent 266b705 commit 72e8571
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/std_constr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,39 @@ void WriteVar(Writer& pr, const char* name,
void WriteModelItem(fmt::MemoryWriter& wrt, const LinTerms& lt,
const std::vector<std::string>& vnam) {
for (int i=0; i<(int)lt.size(); ++i) {
auto coef = lt.coef(i);
bool ifpos = coef>=0.0;
if (i) {
wrt << (lt.coef(i)>=0.0 ? " + " : " - ");
wrt << (ifpos ? " + " : " - ");
} else {
if (!ifpos)
wrt << "-";
}
wrt << std::fabs(lt.coef(i)) << '*' << vnam.at(lt.var(i));
auto abscoef = std::fabs(coef);
if (1.0 != abscoef)
wrt << abscoef << '*';
wrt << vnam.at(lt.var(i));
}
}

void WriteModelItem(fmt::MemoryWriter& wrt, const QuadTerms& qt,
const std::vector<std::string>& vnam) {
for (int i=0; i<(int)qt.size(); ++i) {
auto coef = qt.coef(i);
bool ifpos = coef>=0.0;
if (i) {
wrt << (qt.coef(i)>=0.0 ? " + " : " - ");
}
wrt << std::fabs(qt.coef(i))
<< '*' << vnam.at(qt.var1(i))
<< '*' << vnam.at(qt.var2(i));
} else
if (!ifpos)
wrt << "-";
auto abscoef = std::fabs(coef);
if (1.0 != abscoef)
wrt << abscoef << '*';
if (qt.var1(i)==qt.var2(i))
wrt << vnam.at(qt.var1(i)) << "^2";
else
wrt << vnam.at(qt.var1(i))
<< '*' << vnam.at(qt.var2(i));
}
}

Expand Down

0 comments on commit 72e8571

Please sign in to comment.