-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExactSolver
42 lines (30 loc) · 1.31 KB
/
ExactSolver
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
```markdown
### D-Wave Training Project
#### Objective
The goal of this project was to solve a constraint satisfaction problem using D-Wave's quantum computing libraries.
#### Code Snippet
```python
import dimod
import dwavebinarycsp
# Define the graph
edges = [('0', '1'), ('0', '2'), ('0', '3'), ('1', '2'), ('1', '3'), ('2', '3')]
# Create a binary constraint satisfaction problem (CSP)
csp = dwavebinarycsp.ConstraintSatisfactionProblem(dwavebinarycsp.BINARY)
# Add constraints for equal-sized subsets
# Add objective function for minimizing the number of edges between subsets
# Convert the CSP to a binary quadratic model (BQM)
bqm = dwavebinarycsp.stitch(csp)
# Set up the solver and solve the problem
solver = dimod.ExactSolver()
solution = solver.sample(bqm)
# Print the solutions
for sample, energy in solution.data(['sample', 'energy']):
print(sample, energy)
```
#### Mathematical Explanation
The graph edges are represented by the set \( \left\{ ('0', '1'), ('0', '2'), ('0', '3'), ('1', '2'), ('1', '3'), ('2', '3') \right\} \).
#### Resources
- [Gist for this project](https://gist.github.com/ec9b043b5ed5b1bc02a11198b4efb4a8)
- [Additional Information](https://davidmerwin.pieces.cloud/?p=071f45aa12)
## Contact
Feel free to reach out to me for collaborations, questions, or to chat about quantum computing!