Skip to content

Commit 5106cc1

Browse files
committed
merge latest in
1 parent b9e3cd0 commit 5106cc1

File tree

17 files changed

+533
-27
lines changed

17 files changed

+533
-27
lines changed

BUILD.bazel

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
12
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
23
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
4+
load("@rules_cuda//cuda:defs.bzl", "cuda_library", "requires_cuda")
35

46
copy_file(
57
name = "highs-config",
@@ -8,12 +10,43 @@ copy_file(
810
visibility = ["//visibility:public"],
911
)
1012

13+
bool_flag(
14+
name = "cupdlp_gpu",
15+
build_setting_default = False,
16+
visibility = ["//visibility:public"],
17+
)
18+
19+
config_setting(
20+
name = "cupdlp_gpu_enabled",
21+
flag_values = {
22+
"@rules_cuda//cuda:enable": "True",
23+
"@local_cuda//:valid_toolchain_found": "True",
24+
":cupdlp_gpu": "True",
25+
},
26+
)
27+
1128
cc_library(
1229
name = "config",
1330
srcs = ["HConfig.h"],
1431
visibility = ["//visibility:public"],
1532
)
1633

34+
cuda_library(
35+
name = "cupdlp",
36+
srcs = glob([
37+
"highs/pdlp/cupdlp/cuda/*.cu",
38+
]),
39+
hdrs = glob([
40+
"highs/pdlp/cupdlp/cuda/*.cuh",
41+
]),
42+
defines = ["CUPDLP_GPU"],
43+
target_compatible_with = requires_cuda(),
44+
deps = [
45+
"@local_cuda//:cublas",
46+
"@local_cuda//:cusparse",
47+
],
48+
)
49+
1750
cc_library(
1851
name = "highs",
1952
srcs = ["highs/interfaces/highs_c_api.cpp"] + glob([
@@ -49,6 +82,10 @@ cc_library(
4982
"-Wno-unused-but-set-variable",
5083
],
5184
}),
85+
defines = select({
86+
":cupdlp_gpu_enabled": ["CUPDLP_GPU"],
87+
"//conditions:default": ["CUPDLP_CPU"],
88+
}),
5289
includes = [
5390
"extern",
5491
# "extern/filereaderlp",
@@ -66,7 +103,6 @@ cc_library(
66103
# "highs/simplex",
67104
# "highs/test_kkt",
68105
# "highs/util",
69-
"bazel-bin",
70106
],
71107
linkopts = select({
72108
"@rules_cc//cc/compiler:msvc-cl": ["-DEFAULTLIB:shell32.lib"],
@@ -76,7 +112,10 @@ cc_library(
76112
deps = [
77113
"//:config",
78114
"@zlib",
79-
],
115+
] + select({
116+
":cupdlp_gpu_enabled": [":cupdlp"],
117+
"//conditions:default": [],
118+
}),
80119
)
81120

82121
cc_library(

MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,14 @@ bazel_dep(
1919
name = "zlib",
2020
version = "1.3.1.bcr.5",
2121
)
22+
23+
bazel_dep(
24+
name = "rules_cuda",
25+
version = "0.2.5",
26+
)
27+
28+
local_cuda = use_extension("@rules_cuda//cuda:extensions.bzl", "toolchain")
29+
local_cuda.local_toolchain(
30+
toolkit_path = "",
31+
)
32+
use_repo(local_cuda, "local_cuda")

check/TestBasis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,15 @@ TEST_CASE("Basis-read", "[highs_basis_data]") {
335335
HighsBasisStatus status_before = HighsBasisStatus::kNonbasic;
336336
HighsBasisStatus status_after = HighsBasisStatus::kBasic;
337337
Highs h1;
338+
h1.setOptionValue("output_flag", dev_run);
338339
const HighsBasis& basis1 = h1.getBasis();
339340
h1.passModel(lp);
340341
REQUIRE(basis1.col_status[0] == status_before);
341342
h1.run();
342343
REQUIRE(basis1.col_status[0] == status_after);
343344

344345
Highs h2;
346+
h2.setOptionValue("output_flag", dev_run);
345347
const HighsBasis& basis2 = h2.getBasis();
346348
h2.passModel(lp);
347349
REQUIRE(basis2.col_status[0] == status_before);

check/TestCAPI.c

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,6 @@ void testGetModel() {
18201820
assert(ck_sense == sense);
18211821

18221822
double* ck_col_cost = (double*)malloc(sizeof(double) * ck_num_col);
1823-
;
18241823
double* ck_col_lower = (double*)malloc(sizeof(double) * ck_num_col);
18251824
double* ck_col_upper = (double*)malloc(sizeof(double) * ck_num_col);
18261825
double* ck_row_lower = (double*)malloc(sizeof(double) * ck_num_row);
@@ -2242,6 +2241,115 @@ void testIis() {
22422241
Highs_destroy(highs);
22432242
}
22442243

2244+
void testFixedLp() {
2245+
// The use of Highs_getFixedLp is illustrated for the MIP
2246+
//
2247+
// Min f = -3x_0 - 2x_1 - x_2
2248+
// s.t. x_0 + x_1 + x_2 <= 7
2249+
// 4x_0 + 2x_1 + x_2 = 12
2250+
// x_0 >=0; x_1 >= 0; x_2 binary
2251+
2252+
const HighsInt num_col = 3;
2253+
const HighsInt num_row = 2;
2254+
const HighsInt num_nz = 6;
2255+
HighsInt a_format = kHighsMatrixFormatColwise;
2256+
HighsInt sense = kHighsObjSenseMinimize;
2257+
double offset = 0;
2258+
2259+
// Define the column costs, lower bounds and upper bounds
2260+
double col_cost[3] = {-3.0, -2.0, -1.0};
2261+
double col_lower[3] = {0.0, 0.0, 0.0};
2262+
double col_upper[3] = {1.0e30, 1.0e30, 1.0};
2263+
// Define the row lower bounds and upper bounds
2264+
double row_lower[2] = {-1.0e30, 12.0};
2265+
double row_upper[2] = {7.0, 12.0};
2266+
// Define the constraint matrix column-wise
2267+
HighsInt a_start[3] = {0, 2, 4};
2268+
HighsInt a_index[6] = {0, 1, 0, 1, 0, 1};
2269+
double a_value[6] = {1.0, 4.0, 1.0, 2.0, 1.0, 1.0};
2270+
HighsInt integrality[3] = {kHighsVarTypeContinuous, kHighsVarTypeContinuous,
2271+
kHighsVarTypeInteger};
2272+
2273+
void* highs = Highs_create();
2274+
Highs_setBoolOptionValue(highs, "output_flag", dev_run);
2275+
Highs_setStringOptionValue(highs, "presolve", "off");
2276+
HighsInt return_status =
2277+
Highs_passMip(highs, num_col, num_row, num_nz, a_format, sense, offset,
2278+
col_cost, col_lower, col_upper, row_lower, row_upper,
2279+
a_start, a_index, a_value, integrality);
2280+
assert(return_status == kHighsStatusOk);
2281+
return_status = Highs_run(highs);
2282+
double mip_objective_function_value;
2283+
return_status = Highs_getDoubleInfoValue(highs, "objective_function_value",
2284+
&mip_objective_function_value);
2285+
assert(return_status == kHighsStatusOk);
2286+
2287+
double* col_value = (double*)malloc(sizeof(double) * num_col);
2288+
return_status = Highs_getSolution(highs, col_value, NULL, NULL, NULL);
2289+
assert(return_status == kHighsStatusOk);
2290+
2291+
HighsInt fixed_lp_num_col;
2292+
HighsInt fixed_lp_num_row;
2293+
HighsInt fixed_lp_num_nz;
2294+
HighsInt fixed_lp_sense;
2295+
double fixed_lp_offset;
2296+
Highs_getFixedLp(highs, kHighsMatrixFormatColwise, &fixed_lp_num_col, &fixed_lp_num_row,
2297+
&fixed_lp_num_nz, &fixed_lp_sense, &fixed_lp_offset, NULL, NULL, NULL, NULL, NULL,
2298+
NULL, NULL, NULL);
2299+
2300+
assert(fixed_lp_num_col == num_col);
2301+
assert(fixed_lp_num_row == num_row);
2302+
assert(fixed_lp_num_nz == num_nz);
2303+
assert(fixed_lp_sense == sense);
2304+
2305+
double* fixed_lp_col_cost = (double*)malloc(sizeof(double) * fixed_lp_num_col);
2306+
double* fixed_lp_col_lower = (double*)malloc(sizeof(double) * fixed_lp_num_col);
2307+
double* fixed_lp_col_upper = (double*)malloc(sizeof(double) * fixed_lp_num_col);
2308+
double* fixed_lp_row_lower = (double*)malloc(sizeof(double) * fixed_lp_num_row);
2309+
double* fixed_lp_row_upper = (double*)malloc(sizeof(double) * fixed_lp_num_row);
2310+
HighsInt* fixed_lp_a_start = (HighsInt*)malloc(sizeof(HighsInt) * fixed_lp_num_col);
2311+
HighsInt* fixed_lp_a_index = (HighsInt*)malloc(sizeof(HighsInt) * fixed_lp_num_nz);
2312+
double* fixed_lp_a_value = (double*)malloc(sizeof(double) * num_nz);
2313+
2314+
// Get the arrays
2315+
Highs_getFixedLp(highs, kHighsMatrixFormatColwise, &fixed_lp_num_col, &fixed_lp_num_row,
2316+
&fixed_lp_num_nz, &fixed_lp_sense, &fixed_lp_offset, fixed_lp_col_cost, fixed_lp_col_lower,
2317+
fixed_lp_col_upper, fixed_lp_row_lower, fixed_lp_row_upper, fixed_lp_a_start, fixed_lp_a_index,
2318+
fixed_lp_a_value);
2319+
2320+
return_status = Highs_passLp(highs,
2321+
fixed_lp_num_col, fixed_lp_num_row, fixed_lp_num_nz,
2322+
kHighsMatrixFormatColwise,
2323+
fixed_lp_sense, fixed_lp_offset,
2324+
fixed_lp_col_cost, fixed_lp_col_lower, fixed_lp_col_upper,
2325+
fixed_lp_row_lower, fixed_lp_row_upper,
2326+
fixed_lp_a_start, fixed_lp_a_index, fixed_lp_a_value);
2327+
assert(return_status == kHighsStatusOk);
2328+
2329+
return_status = Highs_setSolution(highs, col_value, NULL, NULL, NULL);
2330+
assert(return_status == kHighsStatusOk);
2331+
2332+
return_status = Highs_run(highs);
2333+
double objective_function_value;
2334+
return_status = Highs_getDoubleInfoValue(highs, "objective_function_value",
2335+
&objective_function_value);
2336+
assert(return_status == kHighsStatusOk);
2337+
assert(objective_function_value == mip_objective_function_value);
2338+
2339+
2340+
free(col_value);
2341+
free(fixed_lp_col_cost);
2342+
free(fixed_lp_col_lower);
2343+
free(fixed_lp_col_upper);
2344+
free(fixed_lp_row_lower);
2345+
free(fixed_lp_row_upper);
2346+
free(fixed_lp_a_start);
2347+
free(fixed_lp_a_index);
2348+
free(fixed_lp_a_value);
2349+
2350+
Highs_destroy(highs);
2351+
}
2352+
22452353
int main() {
22462354
minimalApiIllegalLp();
22472355
testCallback();
@@ -2265,7 +2373,8 @@ int main() {
22652373
testQpIndefiniteFailure();
22662374
testDualRayTwice();
22672375
testDeleteRowResolveWithBasis();
2268-
testIis();
2376+
testIis();
2377+
testFixedLp();
22692378
return 0;
22702379
}
22712380
// testSetSolution();

check/TestIpm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ TEST_CASE("test-2527", "[highs_ipm]") {
213213
std::string filename =
214214
std::string(HIGHS_DIR) + "/check/instances/primal1.mps";
215215
Highs h;
216-
// h.setOptionValue("output_flag", dev_run);
216+
h.setOptionValue("output_flag", dev_run);
217217
REQUIRE(h.readModel(filename) == HighsStatus::kOk);
218218
HighsLp lp = h.getLp();
219219
lp.col_cost_.assign(lp.num_col_, 0);

0 commit comments

Comments
 (0)