Skip to content

Commit fb6b8e6

Browse files
adjusted examples, updated README
1 parent bec876c commit fb6b8e6

File tree

11 files changed

+63
-93
lines changed

11 files changed

+63
-93
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,29 @@ The `qubo_solve.gms` requires the following 5 positional arguments. Since they a
3030
4. objectiveVariable
3131
5. Penalty factor for the constraints
3232

33-
Following is the list of optional `key=val` pair arguments, some of which are method specific.
33+
Following is the list of optional `-key=val` pair arguments, some of which are method specific.
3434

3535
6. method, [qpu, classic] (default: classic)
36-
7. solver, choice of miqcp solver (default: cplex | effective only if `method=classic`).
37-
8. max_iter, Number of times the problem is solved on the QPU (default: 1 | effective only if `method=qpu`)
36+
7. solver, choice of miqcp solver (default: cplex | effective only if `-method=classic`).
37+
8. maxIter, Number of times the problem is solved on the QPU (default: 1 | effective only if `-method=qpu`)
3838
9. timeLimit, Time limit for 1 iteration on QPU or TimeLimit for a classical solve (default: 10)
39-
10. num_threads, Number of threads to be used in case of a classical solve (default: 1 | effective only if method=classic`)
40-
11. log_on, Creates a log for the reformulation [0, 1, 2] (default: 0, don't create a log)
41-
12. examiner_on, [0, 1] (default: 0) The quality of returned qubo solution w.r.t the original problem can be checked through the use of `examiner` [tool](https://www.gams.com/latest/docs/S_EXAMINER.html).
39+
10. numThreads, Number of threads to be used in case of a classical solve (default: min(8,num_of_cores) | effective only if `-method=classic`)
40+
11. logOn, Creates a log for the reformulation [0, 1, 2] (default: 0, don't create a log)
41+
12. examinerOn, [0, 1] (default: 0) The quality of returned qubo solution w.r.t the original problem can be checked through the use of `examiner` [tool](https://www.gams.com/latest/docs/S_EXAMINER.html).
4242

4343
Note: Generating the API key and setting up the Python-Dwave Environment is considered to be available when chosen method of solving is `qpu`.
4444

45+
## How to run
46+
47+
- Download GAMS from https://www.gams.com/download/
48+
- Install GAMS
49+
- Run the main gms file with the desired options by including them in the main file through the `$batinclude` statement. For e.g., `$batinclude qubo_solve.gms setPacking MIP max z 6 -solver=cplex -timeLimit=60 -numThreads=2 -logOn=2`
50+
- from GAMS Studio: Open the main problem file in GAMS studio. If qubo_solve.gms is not in the same directory as the main problem file, enter `-IDIR=<path//to//qubo_solve.gms>` in the [parameter editor](https://www.gams.com/latest/docs/T_STUDIO.html#STUDIO_TOOLBAR) and hit the run button (or press F9)
51+
- from the command line
52+
```
53+
gams '.\QAP.gms' -IDIR=<path//to//qubo_solve.gms>
54+
```
55+
4556
## Output
4657
4758
The script generates two gdx files. One for the standard problem which is saved as `modelName.gdx` and another for the reformulted model, saved as `qout_modeName.gdx`. A successful run will then return the level of binary variables and the objective variable.

examples/01program.gms

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Model zeroOneProblem /all/;
2323

2424
*Solve zeroOneProblem use mip max z;
2525

26-
$batInclude qubo_solve zeroOneProblem MIP max z 10
26+
option limrow=0, limcol=0;
27+
28+
$batinclude '..\qubo_solve.gms' zeroOneProblem MIP max z 10
2729

2830
display x.l, z.l;

examples/Q01.gms

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Model quadZeroOne /all/;
3232
*option miqcp=cplex;
3333
*Solve quadZeroOne use miqcp min z;
3434

35-
$batInclude qubo_solve quadZeroOne MIQCP min z 10
35+
option limrow=0, limcol=0;
36+
37+
$batinclude '..\qubo_solve.gms' quadZeroOne MIQCP min z 10
3638

3739
display x.l, z.l;

examples/QAP.gms

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ c2(i).. sum(j, x(i,j)) =E= 1;
3030

3131
Model qap /all/;
3232

33-
*option miqcp=cplex;
34-
*solve qap min z use miqcp;
33+
option limrow=0, limcol=0;
3534

36-
$batInclude qubo_solve qap MIQCP min z 200
35+
$batinclude '..\qubo_solve.gms' qap MIQCP min z 200
3736

3837
display x.l, z.l;

examples/QKP.gms

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Model qkp /all/;
2323
*option miqcp=cplex;
2424
*solve qkp using miqcp max z;
2525

26-
$batinclude qubo_solve qkp miqcp max z 10
26+
option limrow=0, limcol=0;
27+
28+
$batinclude '..\qubo_solve.gms' qkp miqcp max z 10
2729

2830
display x.l, z.l;

examples/generalIP.gms

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ c3.. sum(i, newX(i)) =G= 3;
3131
model demo_model /all/;
3232

3333
*solve demo_model using mip max z;
34-
$batinclude qubo_solve demo_model mip max z 10
34+
option limrow=0, limcol=0;
35+
36+
$batinclude '..\qubo_solve.gms' demo_model mip max z 10

examples/knights.gms

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -57,46 +57,8 @@ option optCr = 0, optCa = .999;
5757

5858
*solve knight using mip max total;
5959

60-
$batinclude qubo_solve knight mip max total 1 qpu "" 10
60+
option limrow=0, limcol=0;
6161

62-
display total.l;
63-
*solve knightx using mip max total;
62+
$batinclude '..\qubo_solve.gms' knight mip max total 1 -method=qpu -timeLimit=10
6463

65-
$exit
66-
67-
* Now we try to see how many different ways are there to arrange
68-
* the same number of knights.
69-
70-
Scalar maxknight;
71-
maxknight = total.l;
72-
total.lo = total.l - 0.5;
73-
74-
option optCr = 1, optCa = 100, limCol = 0, limRow = 0, solPrint = off;
75-
76-
Set
77-
ss 'max number of solutions groups' / seq1*seq20 /
78-
s(ss) 'dynamic set for solution groups';
79-
80-
Parameter cutval 'all possible solutions for cut generation';
81-
82-
Equation cut(ss) 'known solutions to be eliminated';
83-
84-
cut(s).. sum((i,j), cutval(s,i,j)*x(i,j)) =l= maxknight - 1;
85-
86-
Model knight1 / deftotal, defmovex, cut /;
87-
88-
s(ss) = no;
89-
total.lo = maxknight - .5;
90-
knight1.solveStat = %solveStat.normalCompletion%;
91-
knight1.modelStat = %modelStat.optimal%;
92-
93-
loop(ss$(knight1.solveStat = %solveStat.normalCompletion% and
94-
(knight1.modelStat = %modelStat.optimal% or
95-
knight1.modelStat = %modelStat.integerSolution%)),
96-
s(ss) = yes;
97-
cutval(ss,i,j) = x.l(i,j);
98-
solve knight1 maximizing total using mip;
99-
);
100-
101-
option cutval:0:0:1;
102-
display cutval;
64+
display total.l;

examples/qplib_5881.gms

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,8 @@ $if NOT '%gams.u1%' == '' $include '%gams.u1%'
446446
qplib_5881.tolproj = 0.0;
447447
$if not set MIQCP $set MIQCP MIQCP
448448

449-
*
450-
*$onEcho>convert.opt
451-
*dumpgdx 5881.gdx
452-
*GDXQuadratic 1
453-
*$offEcho
454-
*
455-
*option miqcp=convert;
456-
*
457-
*m.optfile=1;
458-
*m.reslim=5;
459-
*
460449
*Solve qplib_5881 using %MIQCP% maximizing objvar;
461450

462-
$batInclude qubo_solve qplib_5881 miqcp max objvar 1
451+
$batinclude '..\qubo_solve.gms' qplib_5881 miqcp max objvar 1
463452

464453
display objvar.l;

examples/setPacking.gms

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ Model setPacking /all/;
1818

1919
*Solve setPacking using mip max z;
2020

21-
$set method classic
22-
$set solver cplex
23-
$set max_iter 1
24-
$set timeLimit 60
25-
$set num_threads 3
26-
$set log_on 2
27-
28-
$batInclude qubo_solve setPacking MIP max z 6 %method% %solver% %max_iter% %timeLimit% %num_threads% %log_on%
21+
option limrow=0, limcol=0;
22+
23+
$batinclude '..\qubo_solve.gms' setPacking MIP max z 6 -solver=cplex -timeLimit=60 -numThreads=2 -logOn=2
2924

3025
display x.l, z.l;

examples/setPartition.gms

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Model setPartition /all/;
2222

2323
*Solve setPartition use MIP min z;
2424

25-
$batInclude qubo_solve setPartition MIP min z 10
25+
option limrow=0, limcol=0;
26+
27+
$batinclude '..\qubo_solve.gms' setPartition MIP min z 10
2628

2729
display x.l, z.l;

0 commit comments

Comments
 (0)