7 #include <boost/program_options.hpp>
14 namespace po = boost::program_options;
20 int main(
int argc,
char **argv) {
21 po::options_description desc(
22 "Solve a randomly generated Graph Coloring Problem using the QUBO++ Easy "
26 (
"help,h",
"Display this help message.")
27 (
"nodes,n", po::value<uint32_t>()->default_value(100),
"Specify the number of nodes.")
28 (
"proximity,p", po::value<uint32_t>()->default_value(20),
"Specify the proximity between nodes.")
29 (
"Circle,C",
"Arrange nodes in a circular layout.")
30 (
"Delaunay,D",
"Connect nodes using Delaunay triangulation.")
31 (
"colors,c", po::value<uint32_t>()->default_value(4),
"Specify the number of colors to use.")
32 (
"time,t", po::value<uint32_t>()->default_value(10),
"Set the time limit in seconds.")
33 (
"seed,s", po::value<uint32_t>(),
"Set the initial random seed to reproduce the generated map.")
34 (
"output,o", po::value<std::string>(),
"Specify the output file (e.g., png, svg) to save the solution.");
39 po::store(po::parse_command_line(argc, argv, desc), vm);
40 }
catch (
const std::exception &e) {
41 std::cout <<
"Wrong arguments. Please use -h/--help option to see the "
47 if (vm.count(
"help")) {
48 std::cout << desc << std::endl;
53 uint32_t node_count = vm[
"nodes"].as<uint32_t>();
55 uint32_t time_limit = vm[
"time"].as<uint32_t>();
57 uint32_t color_count = vm[
"colors"].as<uint32_t>();
60 if (vm.count(
"problem_seed")) {
66 std::cout <<
"Generating random graph with " << node_count <<
" nodes"
72 if (vm.count(
"Delaunay")) {
79 std::cout <<
"Variables = " << model.
var_count()
81 <<
" Quadratic Terms = " << model.
term_count(2) << std::endl;
83 if (vm.count(
"easy_solver_seed")) {
85 vm[
"easy_solver_seed"].as<uint32_t>());
96 auto sol = solver.
search();
99 graph_color_map.
print();
101 if (vm.count(
"output") > 0) {
102 std::cout <<
"Writing the solution to " << vm[
"output"].as<std::string>()
104 graph_color_map.
draw(vm[
"output"].as<std::string>());
vindex_t var_count() const
size_t term_count(vindex_t deg) const
void set_target_energy(energy_t energy)
void enable_default_callback()
void set_time_limit(uint32_t limit)
Class to store a graph with node coloring and related information.
void gen_proximity_edges(uint32_t proximity)
Create an edges between nodes that are close to each other.
void gen_delaunay_edges()
Create edges between nodes using the Delaunay triangulation.
void draw(const std::string &filename)
Draw the graph in a file.
void gen_random_map(uint32_t n, bool is_circle=false)
Generate a random map with n nodes.
void print()
Displays the histogram of the colors.
void set_color_histogram(const GraphColorQuadModel &model, const qbpp::Sol &sol)
Set the color histogram of the nodes.
Class to store the QUBO expression with variables for the Graph Coloring Problem.
static void set_seed(uint32_t seed=1)
int main(int argc, char **argv)
Main function to generate a random map and solve the Graph Coloring Problem using the Easy Solver.
QUBO++, a C++ library for generating expressions for binary and spin variables.
Easy QUBO Solver for solving QUBO problems.
A miscellaneous library used for sample programs of the QUBO++ library.