Skip to content

Commit

Permalink
fix: Add workaround for Dwave Qubo Solver as it doesn't process the f…
Browse files Browse the repository at this point in the history
…inal "End" statement in the LP file format properly
  • Loading branch information
Elscrux committed Dec 29, 2024
1 parent 3373a76 commit 793ec92
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public String getName() {

@Override
public List<SolverSetting> getSolverSettings() {
return List.of(
return List.of(
new TextSetting(
SETTING_DWAVE_TOKEN,
"The D-Wave token to use, needed to access the D-Wave hardware"
Expand All @@ -88,19 +88,25 @@ public Mono<Solution<String>> solve(

// this field is only relevant when a dwaveToken is added
// (a token is needed to access the d-wave hardware)
var dwaveAnnealingMethod = properties
final var dwaveAnnealingMethod = properties
.<SelectSetting<AnnealingMethod>>getSetting(SETTING_ANNNEALING_METHOD)
.map(SelectSetting::getSelectedOption)
.orElse(DEFAULT_ANNEALING_METHOD);

var solution = new Solution<>(this);
final var solution = new Solution<>(this);

var processRunner = context.getBean(PythonProcessRunner.class, scriptPath);

if (dwaveToken.isPresent() && !dwaveToken.get().isEmpty()) {
processRunner.withEnvironmentVariable("DWAVE_API_TOKEN", dwaveToken.get());
}

// Remove "End" at the end of the input as python script can't handle it
input = input.trim();
if (input.endsWith("End")) {
input = input.substring(0, input.length() - 3);
}

var processResult = processRunner
.withArguments(
ProcessRunner.INPUT_FILE_PATH,
Expand Down

0 comments on commit 793ec92

Please sign in to comment.