Skip to content

Commit 70c8766

Browse files
committed
add instructions to run benchmarks
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
1 parent 16c36b6 commit 70c8766

3 files changed

Lines changed: 114 additions & 2 deletions

File tree

generate-cfcnfp.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
if [ $# -ne 2 ]; then
4+
echo "Usage: $0 N_CONSTRAINTS HAVE_ACTIVATION_COSTS"
5+
exit 1
6+
fi
7+
8+
# Generate a Constrained Fixed Charge Network Flow Problem set
9+
10+
# number of node
11+
TOP_N=30
12+
13+
# number of arcs
14+
TOP_M=100
15+
16+
# maximum capacity
17+
MAX_CAP=10000
18+
19+
# maximum cost
20+
MAX_COST=100
21+
22+
# to make activation cost competitive with linear cost we need
23+
# <MAX_CAP><MAX_COST> ~ <MAX_CHARGE>
24+
25+
# maximum fixed charge
26+
if [ "$2" == "Y" ]; then
27+
MAX_CHARGE=100000
28+
else
29+
MAX_CHARGE=0
30+
fi
31+
32+
# number of constraints
33+
# not much sense in this, because we already want to optimize this quantity and
34+
# we have let the constrait for this quantity to be very loose 0.1
35+
36+
N_CONSTRAINTS=$1
37+
38+
COPIES=1000
39+
40+
repeat(){
41+
for i in `seq 2 ${N_CONSTRAINTS}`;do
42+
echo -n "$1 ";
43+
done
44+
}
45+
46+
for i in `seq ${COPIES}`;
47+
do
48+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.01`
49+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.25`
50+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.5`
51+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.6`
52+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.7`
53+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.8`
54+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.85`
55+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.90`
56+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.95`
57+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.96`
58+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.97`
59+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.98`
60+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.985`
61+
python ./python/fuzzy-constrained-fcnfp.py ${TOP_N} ${TOP_M} ${MAX_CAP} ${MAX_COST} ${MAX_CHARGE} ${N_CONSTRAINTS} 0.01 `repeat 0.990`
62+
done
63+
64+
echo "0000000000000000"
65+
echo "0 0 0"

readme.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Instructions
2+
3+
Create a virtual env for processing the results in python
4+
```
5+
ptyhon3 -m venv venv
6+
source venv/bin/activate
7+
pip install -r python/requirements.txt
8+
```
9+
10+
Compile the project
11+
```
12+
make
13+
```
14+
115
# Fixed Charge Network Flow Problem
216

317
The Fixed Charge Network Flow Problem (FCNFP) is defined as a Network Flow
@@ -216,6 +230,33 @@ feasible solutions.
216230
![accuracy for 3 side constraint](./plots/cfmcf-3c-1f-accuracy.png)
217231
![success rate for 3 side constraint](./plots/cfmcf-3c-1f-success.png)
218232

233+
To run these benchmarks
234+
```
235+
ACTIVATION_COSTS=N
236+
N_CONSTRAINTS=2
237+
bash generate-cfcnfp.sh ${N_CONSTRAINTS} ${ACTIVATION_COSTS} | tee constrained-fcnfp-n${N_CONSTRAINTS}${ACTIVATION_COSTS}.data | ./example/ex-constrained-fcmcf-validate | tee results-n${N_CONSTRAINTS}${ACTIVATION_COSTS} | python3 scatter-plot-cfcnfp.py ${ACTIVATION_COSTS}
238+
239+
ACTIVATION_COSTS=N
240+
N_CONSTRAINTS=3
241+
bash generate-cfcnfp.sh ${N_CONSTRAINTS} ${ACTIVATION_COSTS} | tee constrained-fcnfp-n${N_CONSTRAINTS}${ACTIVATION_COSTS}.data | ./example/ex-constrained-fcmcf-validate | tee results-n${N_CONSTRAINTS}${ACTIVATION_COSTS} | python3 scatter-plot-cfcnfp.py ${ACTIVATION_COSTS}
242+
243+
ACTIVATION_COSTS=N
244+
N_CONSTRAINTS=4
245+
bash generate-cfcnfp.sh ${N_CONSTRAINTS} ${ACTIVATION_COSTS} | tee constrained-fcnfp-n${N_CONSTRAINTS}${ACTIVATION_COSTS}.data | ./example/ex-constrained-fcmcf-validate | tee results-n${N_CONSTRAINTS}${ACTIVATION_COSTS} | python3 scatter-plot-cfcnfp.py ${ACTIVATION_COSTS}
246+
247+
ACTIVATION_COSTS=Y
248+
N_CONSTRAINTS=2
249+
bash generate-cfcnfp.sh ${N_CONSTRAINTS} ${ACTIVATION_COSTS} | tee constrained-fcnfp-n${N_CONSTRAINTS}${ACTIVATION_COSTS}.data | ./example/ex-constrained-fcmcf-validate | tee results-n${N_CONSTRAINTS}${ACTIVATION_COSTS} | python3 scatter-plot-cfcnfp.py ${ACTIVATION_COSTS}
250+
251+
ACTIVATION_COSTS=Y
252+
N_CONSTRAINTS=3
253+
bash generate-cfcnfp.sh ${N_CONSTRAINTS} ${ACTIVATION_COSTS} | tee constrained-fcnfp-n${N_CONSTRAINTS}${ACTIVATION_COSTS}.data | ./example/ex-constrained-fcmcf-validate | tee results-n${N_CONSTRAINTS}${ACTIVATION_COSTS} | python3 scatter-plot-cfcnfp.py ${ACTIVATION_COSTS}
254+
255+
ACTIVATION_COSTS=Y
256+
N_CONSTRAINTS=4
257+
bash generate-cfcnfp.sh ${N_CONSTRAINTS} ${ACTIVATION_COSTS} | tee constrained-fcnfp-n${N_CONSTRAINTS}${ACTIVATION_COSTS}.data | ./example/ex-constrained-fcmcf-validate | tee results-n${N_CONSTRAINTS}${ACTIVATION_COSTS} | python3 scatter-plot-cfcnfp.py ${ACTIVATION_COSTS}
258+
```
259+
219260

220261
# References
221262

scatter-plot-cfcnfp.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from sys import stdin
23
import math
34
import numpy as np
@@ -6,6 +7,11 @@
67
n_constraints = 0
78
fixed_charge = False
89

10+
assert len(sys.argv)==2
11+
12+
if sys.argv[1]=='Y':
13+
fixed_charge = True
14+
915
def transform_scale(x):
1016
return -np.log2(1.0 - x)
1117

@@ -36,7 +42,7 @@ def plot_scatter(X, Y):
3642
ax.set_xticklabels(X_labels)
3743
ax.set_xlabel("difficulty")
3844
ax.set_ylabel("approximate/best solution ratio")
39-
ax.set_title("%d-constraints solution accuracy (%s activation costs)" % (n_constraints-1,
45+
ax.set_title("%d extra constraints solution accuracy (%s activation costs)" % (n_constraints-1,
4046
"with" if fixed_charge else "without"))
4147

4248
qvalues = np.array([ np.quantile(b, quantiles) for b in boxes ])
@@ -66,7 +72,7 @@ def plot_successrate(X, Y):
6672
ax.set_xticklabels(X_labels)
6773
ax.set_xlabel("difficulty")
6874
ax.set_ylabel("success rate")
69-
ax.set_title("%d-constraints success rate (%s activation costs)" % (n_constraints-1,
75+
ax.set_title("%d extra constraints success rate (%s activation costs)" % (n_constraints-1,
7076
"with" if fixed_charge else "without"))
7177
plt.show()
7278

0 commit comments

Comments
 (0)