Skip to content

Commit

Permalink
remove Column and ROw
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Oct 28, 2024
1 parent c265c00 commit 749599c
Show file tree
Hide file tree
Showing 65 changed files with 738 additions and 1,567 deletions.
9 changes: 5 additions & 4 deletions dev/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
#include "idol/mixed-integer/modeling/models/Model.h"
#include "idol/mixed-integer/modeling/objects/Env.h"
#include "idol/mixed-integer/modeling/expressions/operations/operators.h"
#include "idol/mixed-integer/modeling/constraints/TempCtr.h"
#include <gurobi_c++.h>

using namespace idol;

int main(int t_argc, const char** t_argv) {

Env env;
Model model(env, Model::Storage::RowOriented);
const auto x = model.add_vars(Dim<1>(10), 0., 1., Continuous, "x");
const auto x = model.add_vars(Dim<1>(10), 0., 1., Continuous, 1, "x");

Column col;
col.set_obj(1.);
model.add_var(0, 10, Continuous, col);
LinExpr<Ctr> col;
model.add_var(0, 10, Continuous, 1, col);

for (unsigned int i = 0; i < 9; ++i) {
model.add_ctr(x[i] + x[i+1] >= 0.5);
Expand Down
6 changes: 1 addition & 5 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ add_library(idol STATIC
include/idol/general/utils/Set.h
include/idol/general/utils/exceptions/NotImplemented.h
include/idol/mixed-integer/modeling/expressions/LinExpr.h
include/idol/mixed-integer/modeling/matrix/Row.h
src/mixed-integer/modeling/matrix/Row.cpp
src/mixed-integer/modeling/matrix/Column.cpp
include/idol/mixed-integer/modeling/matrix/Column.h
src/mixed-integer/problems/generalized-assignment-problem/GAP_Instance.cpp
include/idol/mixed-integer/problems/knapsack-problem/KP_Instance.h
src/mixed-integer/problems/knapsack-problem/KP_Instance.cpp
Expand All @@ -38,7 +34,6 @@ add_library(idol STATIC
include/idol/mixed-integer/problems/helpers/distances.h
include/idol/mixed-integer/problems/helpers/parse_delimited.h
include/idol/mixed-integer/modeling/expressions/operations/operators_utils.h
include/idol/mixed-integer/modeling/expressions/QuadExpr.h
include/idol/mixed-integer/modeling/models/Model.h
include/idol/mixed-integer/modeling/objects/Env.h
include/idol/mixed-integer/modeling/variables/Var.h
Expand Down Expand Up @@ -231,6 +226,7 @@ add_library(idol STATIC
include/idol/general/utils/SparseVector.h
include/idol/general/utils/sort.h
include/idol/general/utils/Point.h
src/mixed-integer/modeling/variables/VarVersion.cpp
)

find_package(OpenMP REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <BlisHeuristic.h>
#include <CglCutGenerator.hpp>
#include "idol/mixed-integer/optimizers/callbacks/Callback.h"
#include "idol/mixed-integer/modeling/constraints/TempCtr.h"
#include "impl_MibSFromAPI.h"

namespace idol {
Expand Down Expand Up @@ -96,11 +97,11 @@ class idol::MibSCallbackI : public CallbackI {

for (const auto& cut : m_cuts) {

const auto& row = cut.row();
const double rhs = row.rhs();
const auto& row = cut.lhs();
const double rhs = cut.rhs();

CoinPackedVector lhs;
for (const auto& [var, constant] : row.linear()) {
for (const auto& [var, constant] : row) {
const unsigned int index = model.get_var_index(var);
lhs.insert(index, constant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

#ifdef IDOL_USE_EIGEN

#include "idol/mixed-integer/modeling/expressions/QuadExpr.h"
#include "idol/mixed-integer/modeling/expressions/LinExpr.h"
#include "SquareMatrix.h"

namespace idol {

/*
static std::list<Expr<Var>> to_rotated_quadratic_cone(const QuadExpr<Var> &t_expr) {
// Create index mapping
Expand Down Expand Up @@ -113,7 +113,7 @@ namespace idol {
return result;
}

*/
}

#endif
Expand Down
50 changes: 43 additions & 7 deletions lib/include/idol/mixed-integer/modeling/constraints/CtrVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,57 @@
#ifndef IDOL_CTRVERSION_H
#define IDOL_CTRVERSION_H

#include "TempCtr.h"
#include "idol/mixed-integer/modeling/objects/Version.h"
#include "idol/mixed-integer/modeling/expressions/LinExpr.h"
#include "idol/mixed-integer/modeling/Types.h"

namespace idol {
class CtrVersion;
}

class idol::CtrVersion : public Version, public TempCtr {
class idol::CtrVersion : public Version {
std::unique_ptr<LinExpr<Var>> m_lhs;
CtrType m_type;
double m_rhs = 0.;
public:
CtrVersion(unsigned int t_index, TempCtr&& t_temp_ctr) : Version(t_index), TempCtr(std::move(t_temp_ctr)) {}
CtrVersion(unsigned int t_index, const TempCtr& t_temp_ctr) : Version(t_index), TempCtr(t_temp_ctr) {}
CtrVersion(unsigned int t_index, LinExpr<Var>&& t_lhs, CtrType t_type, double t_rhs)
: Version(t_index),
m_lhs(std::make_unique<LinExpr<Var>>(std::move(t_lhs))),
m_type(t_type),
m_rhs(t_rhs)
{}

using TempCtr::has_row;
using TempCtr::reset_row;
using TempCtr::set_row;
CtrVersion(unsigned int t_index, CtrType t_type, double t_rhs)
: Version(t_index),
m_type(t_type),
m_rhs(t_rhs)
{}

CtrVersion(const CtrVersion& t_src)
: Version(t_src),
m_lhs(t_src.m_lhs ? std::make_unique<LinExpr<Var>>(*t_src.m_lhs) : nullptr),
m_type(t_src.m_type),
m_rhs(t_src.m_rhs) {}

double rhs() const { return m_rhs; }

void set_rhs(double t_rhs) { m_rhs = t_rhs; }

CtrType type() const { return m_type; }

void set_type(CtrType t_type) { m_type = t_type; }

LinExpr<Var>& lhs() { return *m_lhs; }

const LinExpr<Var>& lhs() const { return *m_lhs; }

void set_row(LinExpr<Var>&& t_row) { m_lhs = std::make_unique<LinExpr<Var>>(std::move(t_row)); }

bool has_row() const { return m_lhs != nullptr; }

void set_row(const LinExpr<Var>& t_row) { m_lhs = std::make_unique<LinExpr<Var>>(t_row); }

void reset_row() { m_lhs.reset(); }
};

#endif //IDOL_CTRVERSION_H
39 changes: 16 additions & 23 deletions lib/include/idol/mixed-integer/modeling/constraints/TempCtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#ifndef OPTIMIZE_TEMPCTR_H
#define OPTIMIZE_TEMPCTR_H

#include "idol/mixed-integer/modeling/matrix/Row.h"
#include <ostream>
#include <idol/mixed-integer/modeling/expressions/LinExpr.h>
#include <idol/mixed-integer/modeling/Types.h>

namespace idol {

Expand Down Expand Up @@ -37,12 +38,9 @@ namespace idol {
* ```
*/
class idol::TempCtr {
std::unique_ptr<Row> m_row;
LinExpr<Var> m_lhs;
CtrType m_type = LessOrEqual;
protected:
void set_row(Row&& t_row) { m_row = std::make_unique<Row>(std::move(t_row)); }
bool has_row() const { return (bool) m_row; }
void reset_row() { m_row.reset(); }
double m_rhs = 0.;
public:
/**
* Default constructor.
Expand All @@ -58,13 +56,13 @@ class idol::TempCtr {
* @param t_row The desired row.
* @param t_type The desired constraint type.
*/
TempCtr(Row&& t_row, CtrType t_type) : m_row(std::make_unique<Row>(std::move(t_row))), m_type(t_type) {}
TempCtr(LinExpr<Var>&& t_lhs, CtrType t_type, double t_rhs) : m_lhs(std::move(t_lhs)), m_rhs(t_rhs), m_type(t_type) {}

/**
* Copy constructor.
* @param t_src The object to copy.
*/
TempCtr(const TempCtr& t_src) : m_row(t_src.m_row ? std::make_unique<Row>(*t_src.m_row) : std::unique_ptr<Row>()), m_type(t_src.m_type) {}
TempCtr(const TempCtr& t_src) = default;

/**
* Move constructor.
Expand All @@ -84,24 +82,24 @@ class idol::TempCtr {
*/
TempCtr& operator=(TempCtr&& t_src) noexcept = default;

/**
* Returns the row of the temporary constraint (see Row).
* @return The row of the temporary constraint.
*/
[[nodiscard]] const Row& row() const { return *m_row; }
LinExpr<Var>& lhs() { return m_lhs; }

/**
* Returns the row of the temporary constraint (see Row).
* @return The row of the temporary constraint.
*/
Row& row() { return *m_row; }
const LinExpr<Var>& lhs() const { return m_lhs; }

void set_lhs(LinExpr<Var>&& t_lhs) { m_lhs = std::move(t_lhs); }

/**
* Returns the temporary constraint type.
* @return The temporary constraint type.
*/
[[nodiscard]] CtrType type() const { return m_type; }

double rhs() const { return m_rhs; }

double& rhs() { return m_rhs; }

void set_rhs(double t_rhs) { m_rhs = t_rhs; }

/**
* Sets the type of the temporary constraint.
* @param t_type the desired type.
Expand All @@ -113,11 +111,6 @@ class idol::TempCtr {
m_type = t_type;
}

/**
* Returns true if the temporary constraint is violated by the given solution, false otherwise.
* @param t_solution The solution to check.
*/
[[nodiscard]] bool is_violated(const PrimalPoint& t_solution) const;
};

idol::TempCtr operator<=(idol::Expr<idol::Var, idol::Var>&& t_lhs, idol::Expr<idol::Var, idol::Var>&& t_rhs);
Expand Down
Loading

0 comments on commit 749599c

Please sign in to comment.