-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CSP functionality to the library
Add the ability to solve constraint satisfaction problems (CSPs) to the library. * **Definitions and Search Implementation** - Add `CSPProblem` class in `include/definitions.h` to handle variables, domains, and constraints. - Add `BacktrackingSearch` class in `include/definitions.h` for solving CSPs using backtracking search algorithm. - Implement methods for `CSPProblem` and `BacktrackingSearch` classes in `src/search.cpp`. * **Example and Tests** - Add example CSP problem in `examples/csp_example.cpp` demonstrating the usage of `CSPProblem` and `BacktrackingSearch`. - Add test cases for CSP functionality in `tests/tests.cpp` to ensure correctness and performance. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/velocitatem/Symphony?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
1 parent
f3d7182
commit c612f5d
Showing
4 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "definitions.h" | ||
#include <iostream> | ||
#include <unordered_map> | ||
|
||
int main() { | ||
// Create a CSP problem | ||
CSPProblem csp; | ||
|
||
// Add variables and their domains | ||
csp.add_variable("X", {1, 2, 3}); | ||
csp.add_variable("Y", {1, 2, 3}); | ||
csp.add_variable("Z", {1, 2, 3}); | ||
|
||
// Add constraints | ||
csp.add_constraint([](const std::unordered_map<std::string, int> &assignment) { | ||
return assignment.at("X") != assignment.at("Y"); | ||
}); | ||
csp.add_constraint([](const std::unordered_map<std::string, int> &assignment) { | ||
return assignment.at("Y") != assignment.at("Z"); | ||
}); | ||
csp.add_constraint([](const std::unordered_map<std::string, int> &assignment) { | ||
return assignment.at("X") != assignment.at("Z"); | ||
}); | ||
|
||
// Solve the CSP using backtracking search | ||
BacktrackingSearch search(&csp); | ||
std::unordered_map<std::string, int> solution = search.search(); | ||
|
||
// Print the solution | ||
if (!solution.empty()) { | ||
std::cout << "Solution found:" << std::endl; | ||
for (const auto &pair : solution) { | ||
std::cout << pair.first << " = " << pair.second << std::endl; | ||
} | ||
} else { | ||
std::cout << "No solution found." << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters