-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsolver.py
47 lines (40 loc) · 1.41 KB
/
solver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
from csp_templates import Constraint, BooleanCSP
from typing import List, Optional
class Solver:
"""
Class for solving BooleanCSP.
Main methods:
- forward_check
- solve
- infer_var
"""
def __init__(self):
# Your implementation goes here.
pass
def forward_check(self, csp: BooleanCSP) -> Optional[List[int]]:
"""
Perform forward checking on any unchecked constraints in the given CSP.
Return a list of variables (if any) whose values were inferred.
If a contradiction is found, return None.
"""
# Your implementation goes here.
raise NotImplementedError
def solve(self, csp: BooleanCSP) -> Optional[List[int]]:
"""
Find a solution to the given CSP using backtracking.
The solution will not include values for variables
that do not belong to any constraints.
Return a list of variables whose values were inferred.
If no solution is found, return None.
"""
# Your implementation goes here.
raise NotImplementedError
def infer_var(self, csp: BooleanCSP) -> int:
"""
Infer a value for a single variable
if possible using a proof by contradiction.
If any variable is inferred, return it; otherwise return -1.
"""
# Your implementation goes here.
raise NotImplementedError