Skip to content

Commit 3f403a1

Browse files
committed
Merge branch 'master' of https://github.com/metab0t/PyOptInterface into public
2 parents 1306c9b + f75687b commit 3f403a1

File tree

129 files changed

+3282
-1798
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+3282
-1798
lines changed

include/pyoptinterface/copt_model.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ extern "C"
7272
B(COPT_SetQConstrNames); \
7373
B(COPT_SetNLConstrNames); \
7474
B(COPT_AddMipStart); \
75+
B(COPT_SetNLPrimalStart); \
7576
B(COPT_GetQConstrRhs); \
7677
B(COPT_SetRowLower); \
7778
B(COPT_SetRowUpper); \
@@ -223,7 +224,8 @@ class COPTModel : public OnesideLinearConstraintMixin<COPTModel>,
223224
void decode_graph_prefix_order(ExpressionGraph &graph, const ExpressionHandle &result,
224225
std::vector<int> &opcodes, std::vector<double> &constants);
225226
ConstraintIndex add_single_nl_constraint(ExpressionGraph &graph, const ExpressionHandle &result,
226-
const std::tuple<double, double> &interval, const char *name = nullptr);
227+
const std::tuple<double, double> &interval,
228+
const char *name = nullptr);
227229

228230
void delete_constraint(const ConstraintIndex &constraint);
229231
bool is_constraint_active(const ConstraintIndex &constraint);
@@ -281,6 +283,8 @@ class COPTModel : public OnesideLinearConstraintMixin<COPTModel>,
281283

282284
// MIPStart
283285
void add_mip_start(const Vector<VariableIndex> &variables, const Vector<double> &values);
286+
// NLP start
287+
void add_nl_start(const Vector<VariableIndex> &variables, const Vector<double> &values);
284288

285289
// Modifications of model
286290
// 1. set/get RHS of a constraint

include/pyoptinterface/nleval.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct NonlinearEvaluator
182182
struct GraphHashes
183183
{
184184
std::vector<GraphHash> hashes;
185-
size_t n_hashes_since_last_aggregation;
185+
size_t n_hashes_since_last_aggregation = 0;
186186
} constraint_graph_hashes, objective_graph_hashes;
187187

188188
// length = n_graph_instances

include/pyoptinterface/solver_common.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class OnesideLinearConstraintMixin
4040
{
4141
if (function.degree() >= 2)
4242
{
43-
throw std::runtime_error("add_linear_constraint expects linear expression but receives a quadratic expression.");
43+
throw std::runtime_error("add_linear_constraint expects linear expression but receives "
44+
"a quadratic expression.");
4445
}
4546
ScalarAffineFunction f(function);
4647
return get_base()->add_linear_constraint(f, sense, rhs, name);
@@ -617,7 +618,16 @@ struct CSCMatrix
617618
// Sorting based on column indices
618619
std::vector<IDXT> idx(numnz);
619620
std::iota(idx.begin(), idx.end(), 0);
620-
std::sort(idx.begin(), idx.end(), [&](int i, int j) { return cols[i] < cols[j]; });
621+
std::sort(idx.begin(), idx.end(), [&](int i, int j) {
622+
if (cols[i] == cols[j])
623+
{
624+
return rows[i] < rows[j];
625+
}
626+
else
627+
{
628+
return cols[i] < cols[j];
629+
}
630+
});
621631

622632
// Creating CSC arrays
623633
values_CSC.reserve(numnz);

lib/copt_model.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,28 @@ void COPTModel::add_mip_start(const Vector<VariableIndex> &variables, const Vect
11311131
check_error(error);
11321132
}
11331133

1134+
void COPTModel::add_nl_start(const Vector<VariableIndex> &variables, const Vector<double> &values)
1135+
{
1136+
if (variables.size() != values.size())
1137+
{
1138+
throw std::runtime_error("Number of variables and values do not match");
1139+
}
1140+
int numnz = variables.size();
1141+
if (numnz == 0)
1142+
return;
1143+
1144+
std::vector<int> ind_v(numnz);
1145+
for (int i = 0; i < numnz; i++)
1146+
{
1147+
ind_v[i] = _variable_index(variables[i].index);
1148+
}
1149+
int *ind = ind_v.data();
1150+
double *val = (double *)values.data();
1151+
1152+
int error = copt::COPT_SetNLPrimalStart(m_model.get(), numnz, ind, val);
1153+
check_error(error);
1154+
}
1155+
11341156
double COPTModel::get_normalized_rhs(const ConstraintIndex &constraint)
11351157
{
11361158
int row = _checked_constraint_index(constraint);

lib/copt_model_ext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ NB_MODULE(copt_model_ext, m)
184184
BIND_F(set_obj_sense)
185185

186186
BIND_F(add_mip_start)
187+
BIND_F(add_nl_start)
187188

188189
BIND_F(get_normalized_rhs)
189190
BIND_F(set_normalized_rhs)

lib/copt_model_ext_constants.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void bind_copt_constants(nb::module_ &m)
5151
COPT.attr("INF_OR_UNB") = 4;
5252
COPT.attr("INTEGER") = "I";
5353
COPT.attr("INTERRUPTED") = 10;
54+
COPT.attr("ITERLIMIT") = 11;
5455
COPT.attr("LESS_EQUAL") = "L";
5556
COPT.attr("MAXIMIZE") = -1;
5657
COPT.attr("MINIMIZE") = 1;
@@ -65,9 +66,9 @@ void bind_copt_constants(nb::module_ &m)
6566
COPT.attr("UNDEFINED") = 1e+40;
6667
COPT.attr("UNFINISHED") = 9;
6768
COPT.attr("UNSTARTED") = 0;
68-
COPT.attr("VERSION_MAJOR") = 7;
69-
COPT.attr("VERSION_MINOR") = 2;
70-
COPT.attr("VERSION_TECHNICAL") = 5;
69+
COPT.attr("VERSION_MAJOR") = 8;
70+
COPT.attr("VERSION_MINOR") = 0;
71+
COPT.attr("VERSION_TECHNICAL") = 1;
7172

7273
nb::module_ Attr = COPT.def_submodule("Attr");
7374
Attr.attr("AffineCones") = "AffineCones";
@@ -82,6 +83,7 @@ void bind_copt_constants(nb::module_ &m)
8283
Attr.attr("ExpCones") = "ExpCones";
8384
Attr.attr("FeasRelaxObj") = "FeasRelaxObj";
8485
Attr.attr("HasBasis") = "HasBasis";
86+
Attr.attr("HasBranchFactor") = "HasBranchFactor";
8587
Attr.attr("HasDualFarkas") = "HasDualFarkas";
8688
Attr.attr("HasFeasRelaxSol") = "HasFeasRelaxSol";
8789
Attr.attr("HasIIS") = "HasIIS";
@@ -91,6 +93,7 @@ void bind_copt_constants(nb::module_ &m)
9193
Attr.attr("HasPrimalRay") = "HasPrimalRay";
9294
Attr.attr("HasPsdObj") = "HasPSDObj";
9395
Attr.attr("HasQObj") = "HasQObj";
96+
Attr.attr("HasSensitivity") = "HasSensitivity";
9497
Attr.attr("IISCols") = "IISCols";
9598
Attr.attr("IISIndicators") = "IISIndicators";
9699
Attr.attr("IISRows") = "IISRows";
@@ -103,6 +106,7 @@ void bind_copt_constants(nb::module_ &m)
103106
Attr.attr("LpObjVal") = "LpObjVal";
104107
Attr.attr("LpStatus") = "LpStatus";
105108
Attr.attr("MipStatus") = "MipStatus";
109+
Attr.attr("MultiObjs") = "MultiObjs";
106110
Attr.attr("NLConstrs") = "NLConstrs";
107111
Attr.attr("NLElems") = "NLElems";
108112
Attr.attr("NodeCnt") = "NodeCnt";
@@ -147,13 +151,21 @@ void bind_copt_constants(nb::module_ &m)
147151
Param.attr("IISMethod") = "IISMethod";
148152
Param.attr("IntTol") = "IntTol";
149153
Param.attr("LazyConstraints") = "LazyConstraints";
154+
Param.attr("LinearizeIndicators") = "LinearizeIndicators";
155+
Param.attr("LinearizeSos") = "LinearizeSos";
150156
Param.attr("LogToConsole") = "LogToConsole";
151157
Param.attr("Logging") = "Logging";
152158
Param.attr("LpMethod") = "LpMethod";
153159
Param.attr("MatrixTol") = "MatrixTol";
154160
Param.attr("MipStartMode") = "MipStartMode";
155161
Param.attr("MipStartNodeLimit") = "MipStartNodeLimit";
156162
Param.attr("MipTasks") = "MipTasks";
163+
Param.attr("MultiObjAbsTol") = "MultiObjAbsTol";
164+
Param.attr("MultiObjParamMode") = "MultiObjParamMode";
165+
Param.attr("MultiObjPriority") = "MultiObjPriority";
166+
Param.attr("MultiObjRelTol") = "MultiObjRelTol";
167+
Param.attr("MultiObjTimeLimit") = "MultiObjTimeLimit";
168+
Param.attr("MultiObjWeight") = "MultiObjWeight";
157169
Param.attr("NLPIterLimit") = "NLPIterLimit";
158170
Param.attr("NLPLinScale") = "NLPLinScale";
159171
Param.attr("NLPMuUpdate") = "NLPMuUpdate";
@@ -165,6 +177,7 @@ void bind_copt_constants(nb::module_ &m)
165177
Param.attr("Presolve") = "Presolve";
166178
Param.attr("RelGap") = "RelGap";
167179
Param.attr("ReqFarkasRay") = "ReqFarkasRay";
180+
Param.attr("ReqSensitivity") = "ReqSensitivity";
168181
Param.attr("RootCutLevel") = "RootCutLevel";
169182
Param.attr("RootCutRounds") = "RootCutRounds";
170183
Param.attr("RoundingHeurLevel") = "RoundingHeurLevel";
@@ -187,6 +200,7 @@ void bind_copt_constants(nb::module_ &m)
187200
Param.attr("TuneTimeLimit") = "TuneTimeLimit";
188201

189202
nb::module_ Info = COPT.def_submodule("Info");
203+
Info.attr("BranchFactor") = "BranchFactor";
190204
Info.attr("Dual") = "Dual";
191205
Info.attr("DualFarkas") = "DualFarkas";
192206
Info.attr("LB") = "LB";
@@ -196,6 +210,12 @@ void bind_copt_constants(nb::module_ &m)
196210
Info.attr("RelaxLB") = "RelaxLB";
197211
Info.attr("RelaxUB") = "RelaxUB";
198212
Info.attr("RelaxValue") = "RelaxValue";
213+
Info.attr("SALBLow") = "SALBLow";
214+
Info.attr("SALBUp") = "SALBUp";
215+
Info.attr("SAObjLow") = "SAObjLow";
216+
Info.attr("SAObjUp") = "SAObjUp";
217+
Info.attr("SAUBLow") = "SAUBLow";
218+
Info.attr("SAUBUp") = "SAUBUp";
199219
Info.attr("Slack") = "Slack";
200220
Info.attr("UB") = "UB";
201221
Info.attr("Value") = "Value";

0 commit comments

Comments
 (0)