|
4 | 4 | import os |
5 | 5 |
|
6 | 6 | models = [] |
7 | | -for root, dirs, files in os.walk("."): |
8 | | - for file in files: |
9 | | - if file.endswith(".py") and "PARSER" not in file.upper() and file not in ["createjson.py", "readme.py", "searchmodels.py"]: |
10 | | - model = os.path.join(root, file)[2:] |
11 | | - type = "CSP" |
12 | | - name = os.path.basename(model).split(".")[0] |
13 | | - f = open(model, "r") |
14 | | - lines = f.readlines() |
15 | | - constraints = [] |
16 | | - tags = [] |
17 | | - links = [] |
18 | | - start = False |
19 | | - for line in lines: |
20 | | - stripped = line.strip() |
21 | | - if stripped.startswith("minimize(") or stripped.startswith("maximize("): |
22 | | - type = "COP" |
23 | | - if stripped.startswith("- http"): |
24 | | - links.append(stripped.split("-")[1].strip()) |
25 | | - if stripped.startswith("constraints") or stripped.startswith("Constraints"): |
26 | | - constraints = [c.strip() for c in stripped.split(":")[1].split(',')] |
27 | | - if stripped.startswith("## Tags"): |
28 | | - start = True |
29 | | - elif start: |
30 | | - tags = [t.strip().rstrip(",") for t in stripped.split(" ")] |
31 | | - start = False |
32 | | - f.close() |
33 | | - models.append({"name": name, "fullname": os.path.dirname(model), "constraints" : constraints, "type": type, "tags": tags, "links": links}) |
| 7 | +directories = ["academic", "single", "realistic", "crafted", "recreational"] |
| 8 | + |
| 9 | +for thedir in directories: |
| 10 | + problems = sorted([name for name in os.listdir(thedir) if os.path.isdir(os.path.join(thedir, name))]) |
| 11 | + |
| 12 | + for p in problems: |
| 13 | + dir = f"{thedir}/{p}" |
| 14 | + model = f"{p}.py" if os.path.isfile(f"{dir}/{p}.py") else f"{p}1.py" |
| 15 | + model = dir + "/" + model |
| 16 | + type = "CSP" |
| 17 | + lines = open(model, "r").readlines() |
| 18 | + constraints = [] |
| 19 | + tags = [] |
| 20 | + links = [] |
| 21 | + start = False |
| 22 | + for line in lines: |
| 23 | + stripped = line.strip() |
| 24 | + if stripped.startswith("minimize(") or stripped.startswith("maximize("): |
| 25 | + type = "COP" |
| 26 | + if stripped.startswith("- http"): |
| 27 | + links.append(stripped.split("-")[1].strip()) |
| 28 | + if stripped.startswith("constraints") or stripped.startswith("Constraints"): |
| 29 | + constraints = [c.strip() for c in stripped.split(":")[1].split(',')] |
| 30 | + if stripped.startswith("## Tags"): |
| 31 | + start = True |
| 32 | + elif start: |
| 33 | + tags = [t.strip().rstrip(",") for t in stripped.split(" ")] |
| 34 | + start = False |
| 35 | + models.append( |
| 36 | + {"name": p, "fullname": model, "constraints": constraints, "type": type, "tags": tags, |
| 37 | + "links": links}) |
34 | 38 |
|
35 | 39 | models.sort(key=lambda model: model["name"]) |
36 | 40 | print(json.dumps(models)) |
37 | | - |
|
0 commit comments