修改分支定界搜索过程中,状态未更新导致的找不到最优解的问题
This commit is contained in:
@@ -33,10 +33,10 @@ Expr sv::operator+(const Expr& x, const Expr& y)
|
||||
exp.coeffs.resize(std::max(x.coeffs.size(), y.coeffs.size()), 0);
|
||||
for (int c = 0; c < exp.coeffs.size(); c++) {
|
||||
if (c < x.coeffs.size() && c < y.coeffs.size()) {
|
||||
exp.coeffs[c] = x.coeffs[c] + y.coeffs[c];
|
||||
exp.coeffs.at(c) = x.coeffs.at(c) + y.coeffs.at(c);
|
||||
}
|
||||
else {
|
||||
exp.coeffs[c] = c < x.coeffs.size() ? x.coeffs[c] : y.coeffs[c];
|
||||
exp.coeffs.at(c) = c < x.coeffs.size() ? x.coeffs.at(c) : y.coeffs.at(c);
|
||||
}
|
||||
}
|
||||
exp.constant = x.constant + y.constant;
|
||||
@@ -52,8 +52,8 @@ Expr sv::operator+(Var x, Var y)
|
||||
{
|
||||
Expr exp;
|
||||
exp.coeffs.resize(std::max(x.get(IntAttr::NumCol) + 1, y.get(IntAttr::NumCol) + 1), 0);
|
||||
exp.coeffs[x.get(IntAttr::NumCol)] = x.get(DoubleAttr::Coeff);
|
||||
exp.coeffs[y.get(IntAttr::NumCol)] = y.get(DoubleAttr::Coeff);
|
||||
exp.coeffs.at(x.get(IntAttr::NumCol)) = x.get(DoubleAttr::Coeff);
|
||||
exp.coeffs.at(y.get(IntAttr::NumCol)) = y.get(DoubleAttr::Coeff);
|
||||
return exp;
|
||||
}
|
||||
|
||||
@@ -76,10 +76,10 @@ Expr sv::operator-(const Expr& x, const Expr& y)
|
||||
exp.coeffs.resize(std::max(x.coeffs.size(), y.coeffs.size()), 0);
|
||||
for (int c = 0; c < exp.coeffs.size(); c++) {
|
||||
if (c < x.coeffs.size() && c < y.coeffs.size()) {
|
||||
exp.coeffs[c] = x.coeffs[c] - y.coeffs[c];
|
||||
exp.coeffs.at(c) = x.coeffs.at(c) - y.coeffs.at(c);
|
||||
}
|
||||
else {
|
||||
exp.coeffs[c] = c < x.coeffs.size() ? x.coeffs[c] : y.coeffs[c];
|
||||
exp.coeffs.at(c) = c < x.coeffs.size() ? x.coeffs.at(c) : y.coeffs.at(c);
|
||||
}
|
||||
}
|
||||
exp.constant = x.constant + y.constant;
|
||||
@@ -90,7 +90,7 @@ Expr sv::operator-(const Expr& x)
|
||||
{
|
||||
Expr expr(x);
|
||||
for (int c = 0; c < expr.coeffs.size(); c++) {
|
||||
expr.coeffs[c] = -expr.coeffs[c];
|
||||
expr.coeffs.at(c) = -expr.coeffs.at(c);
|
||||
}
|
||||
expr.constant = -expr.constant;
|
||||
return expr;
|
||||
@@ -105,8 +105,8 @@ Expr sv::operator-(Var x, Var y)
|
||||
{
|
||||
Expr exp;
|
||||
exp.coeffs.resize(std::max(x.get(IntAttr::NumCol) + 1, y.get(IntAttr::NumCol) + 1), 0);
|
||||
exp.coeffs[x.get(IntAttr::NumCol)] = x.get(DoubleAttr::Coeff);
|
||||
exp.coeffs[y.get(IntAttr::NumCol)] = -y.get(DoubleAttr::Coeff);
|
||||
exp.coeffs.at(x.get(IntAttr::NumCol)) = x.get(DoubleAttr::Coeff);
|
||||
exp.coeffs.at(y.get(IntAttr::NumCol)) = -y.get(DoubleAttr::Coeff);
|
||||
return exp;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ Expr sv::operator*(double a, Var x)
|
||||
{
|
||||
Expr exp;
|
||||
exp.coeffs.resize(x.get(IntAttr::NumCol) + 1, 0);
|
||||
exp.coeffs[x.get(IntAttr::NumCol)] = a * x.get(DoubleAttr::Coeff);
|
||||
exp.coeffs.at(x.get(IntAttr::NumCol)) = a * x.get(DoubleAttr::Coeff);
|
||||
return exp;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ Expr sv::operator*(const Expr& x, double a)
|
||||
{
|
||||
Expr exp = x;
|
||||
for (int c = 0; c < exp.coeffs.size(); c++) {
|
||||
exp.coeffs[c] *= a;
|
||||
exp.coeffs.at(c) *= a;
|
||||
}
|
||||
exp.constant *= a;
|
||||
return exp;
|
||||
@@ -157,7 +157,7 @@ Expr sv::operator/(const Expr& x, double a)
|
||||
{
|
||||
Expr exp = x;
|
||||
for (int c = 0; c < exp.coeffs.size(); c++) {
|
||||
exp.coeffs[c] /= a;
|
||||
exp.coeffs.at(c) /= a;
|
||||
}
|
||||
exp.constant /= a;
|
||||
return exp;
|
||||
@@ -171,7 +171,7 @@ Expr::Expr(double constant)
|
||||
Expr::Expr(Var var, double coeff)
|
||||
{
|
||||
this->coeffs.resize(var.col + 1);
|
||||
this->coeffs[var.col] = coeff;
|
||||
this->coeffs.at(var.col) = coeff;
|
||||
this->constant = 0;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ void Expr::operator+=(const Expr& expr)
|
||||
{
|
||||
coeffs.resize(std::max(coeffs.size(), expr.coeffs.size()));
|
||||
for (int c = 0; c < expr.coeffs.size(); c++) {
|
||||
coeffs[c] += expr.coeffs[c];
|
||||
coeffs.at(c) += expr.coeffs.at(c);
|
||||
}
|
||||
constant += expr.constant;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ void Expr::operator-=(const Expr& expr)
|
||||
{
|
||||
coeffs.resize(std::max(coeffs.size(), expr.coeffs.size()));
|
||||
for (int c = 0; c < expr.coeffs.size(); c++) {
|
||||
coeffs[c] -= expr.coeffs[c];
|
||||
coeffs.at(c) -= expr.coeffs.at(c);
|
||||
}
|
||||
constant -= expr.constant;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ void Expr::operator-=(const Expr& expr)
|
||||
void Expr::operator*=(double mult)
|
||||
{
|
||||
for (int c = 0; c < coeffs.size(); c++) {
|
||||
coeffs[c] *= mult;
|
||||
coeffs.at(c) *= mult;
|
||||
}
|
||||
constant *= mult;
|
||||
}
|
||||
@@ -209,7 +209,7 @@ void Expr::operator*=(double mult)
|
||||
void Expr::operator/=(double a)
|
||||
{
|
||||
for (int c = 0; c < coeffs.size(); c++) {
|
||||
coeffs[c] /= a;
|
||||
coeffs.at(c) /= a;
|
||||
}
|
||||
constant /= a;
|
||||
}
|
||||
@@ -218,7 +218,7 @@ Expr Expr::operator+(const Expr& rhs)
|
||||
{
|
||||
coeffs.resize(std::max(coeffs.size(), rhs.coeffs.size()));
|
||||
for (int c = 0; c < rhs.coeffs.size(); c++) {
|
||||
coeffs[c] += rhs.coeffs[c];
|
||||
coeffs.at(c) += rhs.coeffs.at(c);
|
||||
}
|
||||
constant += rhs.constant;
|
||||
return *this;
|
||||
@@ -228,7 +228,7 @@ Expr Expr::operator-(const Expr& rhs)
|
||||
{
|
||||
coeffs.resize(std::max(coeffs.size(), rhs.coeffs.size()));
|
||||
for (int c = 0; c < rhs.coeffs.size(); c++) {
|
||||
coeffs[c] -= rhs.coeffs[c];
|
||||
coeffs.at(c) -= rhs.coeffs.at(c);
|
||||
}
|
||||
constant -= rhs.constant;
|
||||
return *this;
|
||||
|
Reference in New Issue
Block a user