Skip to content
Open
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ set(POI_INSTALL_DIR ${SKBUILD_PLATLIB_DIR}/pyoptinterface/_src)

add_library(core STATIC)
target_sources(core PRIVATE
include/pyoptinterface/cache_model.hpp
include/pyoptinterface/core.hpp
include/pyoptinterface/container.hpp
include/pyoptinterface/dylib.hpp
include/pyoptinterface/oneshot_model.hpp
include/pyoptinterface/solver_common.hpp
lib/cache_model.cpp
lib/core.cpp
lib/oneshot_model.cpp
)
target_include_directories(core PUBLIC include thirdparty)
target_link_libraries(core PUBLIC fmt)
Expand Down
56 changes: 0 additions & 56 deletions include/pyoptinterface/cache_model.hpp

This file was deleted.

48 changes: 44 additions & 4 deletions include/pyoptinterface/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,46 @@ class ChunkedBitVector
return result;
}

// Initialize the first N indices as 1
void init_indices(int N)
{
assert(N >= 0);
if (N == 0)
{
clear();
return;
}

auto N_full_elements = N >> LOG2_CHUNK_WIDTH;
auto N_remaining_bits = N & (CHUNK_WIDTH - 1);

// all bits set to 1
constexpr ChunkT newelement = ~0;

m_data.assign(N_full_elements, newelement);
m_cumulated_ranks.resize(N_full_elements);
for (std::size_t i = 0; i < N_full_elements; i++)
{
m_cumulated_ranks[i] = i * CHUNK_WIDTH + m_start;
}
m_chunk_ranks.assign(N_full_elements, CHUNK_WIDTH);

if (N_remaining_bits > 0)
{
// set the bits in [0, N_remaining_bits) to 1
ChunkT remaining_chunk = (ChunkT{1} << N_remaining_bits) - 1;
m_data.push_back(remaining_chunk);
m_cumulated_ranks.push_back(N_full_elements * CHUNK_WIDTH + m_start);
m_chunk_ranks.push_back(N_remaining_bits);
m_next_bit = N_remaining_bits;
}
else
{
m_next_bit = CHUNK_WIDTH;
}
m_last_correct_chunk = m_data.size() - 1;
}

// Add N new indices, return the start of index
IndexT add_indices(int N)
{
Expand All @@ -201,7 +241,7 @@ class ChunkedBitVector
IndexT result = last_chunk_end + m_next_bit;

// all bits set to 1
ChunkT newelement = ~0;
constexpr ChunkT newelement = ~0;

// The current chunk needs to be filled as 1
int extra_bits_in_current_chunk = CHUNK_WIDTH - m_next_bit;
Expand Down Expand Up @@ -337,9 +377,9 @@ class ChunkedBitVector

void clear()
{
m_data.resize(1, 0);
m_cumulated_ranks.resize(1, m_start);
m_chunk_ranks.resize(1, -1);
m_data.assign(1, 0);
m_cumulated_ranks.assign(1, m_start);
m_chunk_ranks.assign(1, -1);
m_last_correct_chunk = 0;
m_next_bit = 0;
}
Expand Down
5 changes: 4 additions & 1 deletion include/pyoptinterface/copt_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define USE_NLMIXIN
#include "pyoptinterface/solver_common.hpp"
#include "pyoptinterface/dylib.hpp"
#include "pyoptinterface/oneshot_model.hpp"

extern "C"
{
Expand All @@ -29,8 +30,10 @@ extern "C"
B(COPT_WriteMst); \
B(COPT_WriteParam); \
B(COPT_AddCol); \
B(COPT_AddCols); \
B(COPT_DelCols); \
B(COPT_AddRow); \
B(COPT_AddRows); \
B(COPT_AddQConstr); \
B(COPT_AddSOSs); \
B(COPT_AddCones); \
Expand Down Expand Up @@ -189,7 +192,7 @@ class COPTModel : public OnesideLinearConstraintMixin<COPTModel>,
public:
COPTModel() = default;
COPTModel(const COPTEnv &env);
void init(const COPTEnv &env);
COPTModel(const COPTEnv &env, const OneShotModel &model);
void close();

double get_infinity() const;
Expand Down
3 changes: 2 additions & 1 deletion include/pyoptinterface/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ enum class ConstraintSense
{
LessEqual,
GreaterEqual,
Equal
Equal,
Interval
};

struct ConstraintIndex
Expand Down
6 changes: 5 additions & 1 deletion include/pyoptinterface/gurobi_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define USE_NLMIXIN
#include "pyoptinterface/solver_common.hpp"
#include "pyoptinterface/dylib.hpp"
#include "pyoptinterface/oneshot_model.hpp"

// define Gurobi C APIs
#define APILIST \
Expand All @@ -19,8 +20,10 @@
B(GRBgetenv); \
B(GRBwrite); \
B(GRBaddvar); \
B(GRBaddvars); \
B(GRBdelvars); \
B(GRBaddconstr); \
B(GRBaddconstrs); \
B(GRBaddqconstr); \
B(GRBaddsos); \
B(GRBaddgenconstrNL); \
Expand Down Expand Up @@ -153,7 +156,8 @@ class GurobiModel : public OnesideLinearConstraintMixin<GurobiModel>,
public:
GurobiModel() = default;
GurobiModel(const GurobiEnv &env);
void init(const GurobiEnv &env);
// build the model from OneShotModel directly
GurobiModel(const GurobiEnv &env, const OneShotModel &model);
void close();

void _reset(int clearall);
Expand Down
118 changes: 61 additions & 57 deletions include/pyoptinterface/highs_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,66 @@
#include "pyoptinterface/container.hpp"
#include "pyoptinterface/solver_common.hpp"
#include "pyoptinterface/dylib.hpp"

#define APILIST \
B(Highs_create); \
B(Highs_destroy); \
B(Highs_writeModel); \
B(Highs_writeSolution); \
B(Highs_writeSolutionPretty); \
B(Highs_addCol); \
B(Highs_passColName); \
B(Highs_getColName); \
B(Highs_getNumCol); \
B(Highs_changeColIntegrality); \
B(Highs_deleteColsBySet); \
B(Highs_addRow); \
B(Highs_passRowName); \
B(Highs_getRowName); \
B(Highs_getNumRow); \
B(Highs_deleteRowsBySet); \
B(Highs_passHessian); \
B(Highs_changeColsCostByRange); \
B(Highs_changeObjectiveOffset); \
B(Highs_changeObjectiveSense); \
B(Highs_run); \
B(Highs_getNumCols); \
B(Highs_getNumRows); \
B(Highs_getModelStatus); \
B(Highs_getDualRay); \
B(Highs_getPrimalRay); \
B(Highs_getIntInfoValue); \
B(Highs_getSolution); \
B(Highs_getHessianNumNz); \
B(Highs_getBasis); \
B(Highs_version); \
B(Highs_getRunTime); \
B(Highs_getOptionType); \
B(Highs_setBoolOptionValue); \
B(Highs_setIntOptionValue); \
B(Highs_setDoubleOptionValue); \
B(Highs_setStringOptionValue); \
B(Highs_getBoolOptionValue); \
B(Highs_getIntOptionValue); \
B(Highs_getDoubleOptionValue); \
B(Highs_getStringOptionValue); \
B(Highs_getInfoType); \
B(Highs_getInt64InfoValue); \
B(Highs_getDoubleInfoValue); \
B(Highs_getColIntegrality); \
B(Highs_changeColsBoundsBySet); \
B(Highs_getColsBySet); \
B(Highs_getObjectiveSense); \
B(Highs_getObjectiveValue); \
B(Highs_getColsByRange); \
B(Highs_setSolution); \
B(Highs_getRowsBySet); \
B(Highs_changeRowsBoundsBySet); \
B(Highs_changeCoeff); \
#include "pyoptinterface/oneshot_model.hpp"

#define APILIST \
B(Highs_create); \
B(Highs_destroy); \
B(Highs_writeModel); \
B(Highs_writeSolution); \
B(Highs_writeSolutionPretty); \
B(Highs_addCol); \
B(Highs_addCols); \
B(Highs_passColName); \
B(Highs_getColName); \
B(Highs_getNumCol); \
B(Highs_changeColIntegrality); \
B(Highs_changeColsIntegralityByRange); \
B(Highs_deleteColsBySet); \
B(Highs_addRow); \
B(Highs_addRows); \
B(Highs_passRowName); \
B(Highs_getRowName); \
B(Highs_getNumRow); \
B(Highs_deleteRowsBySet); \
B(Highs_passHessian); \
B(Highs_changeColsCostByRange); \
B(Highs_changeObjectiveOffset); \
B(Highs_changeObjectiveSense); \
B(Highs_run); \
B(Highs_getNumCols); \
B(Highs_getNumRows); \
B(Highs_getModelStatus); \
B(Highs_getDualRay); \
B(Highs_getPrimalRay); \
B(Highs_getIntInfoValue); \
B(Highs_getSolution); \
B(Highs_getHessianNumNz); \
B(Highs_getBasis); \
B(Highs_version); \
B(Highs_getRunTime); \
B(Highs_getOptionType); \
B(Highs_setBoolOptionValue); \
B(Highs_setIntOptionValue); \
B(Highs_setDoubleOptionValue); \
B(Highs_setStringOptionValue); \
B(Highs_getBoolOptionValue); \
B(Highs_getIntOptionValue); \
B(Highs_getDoubleOptionValue); \
B(Highs_getStringOptionValue); \
B(Highs_getInfoType); \
B(Highs_getInt64InfoValue); \
B(Highs_getDoubleInfoValue); \
B(Highs_getColIntegrality); \
B(Highs_changeColsBoundsBySet); \
B(Highs_getColsBySet); \
B(Highs_getObjectiveSense); \
B(Highs_getObjectiveValue); \
B(Highs_getColsByRange); \
B(Highs_setSolution); \
B(Highs_getRowsBySet); \
B(Highs_changeRowsBoundsBySet); \
B(Highs_changeCoeff); \
B(Highs_changeColCost);

namespace highs
Expand Down Expand Up @@ -119,7 +123,7 @@ class POIHighsModel : public OnesideLinearConstraintMixin<POIHighsModel>,
{
public:
POIHighsModel();
void init();
POIHighsModel(const OneShotModel &model);
void close();

void write(const std::string &filename, bool pretty);
Expand Down
Loading
Loading