GHOST
Loading...
Searching...
No Matches
model_builder.hpp
Go to the documentation of this file.
1/*
2 * GHOST (General meta-Heuristic Optimization Solving Tool) is a C++ framework
3 * designed to help developers to model and implement optimization problem
4 * solving. It contains a meta-heuristic solver aiming to solve any kind of
5 * combinatorial and optimization real-time problems represented by a CSP/COP/EF-CSP/EF-COP.
6 *
7 * First developed to solve game-related optimization problems, GHOST can be used for
8 * any kind of applications where solving combinatorial and optimization problems. In
9 * particular, it had been designed to be able to solve not-too-complex problem instances
10 * within some milliseconds, making it very suitable for highly reactive or embedded systems.
11 * Please visit https://github.com/richoux/GHOST for further information.
12 *
13 * Copyright (C) 2014-2025 Florian Richoux
14 *
15 * This file is part of GHOST.
16 * GHOST is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as published
18 * by the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20
21 * GHOST is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25
26 * You should have received a copy of the GNU General Public License
27 * along with GHOST. If not, see http://www.gnu.org/licenses/.
28 */
29
30#pragma once
31
32#include <vector>
33#include <memory>
34
35#include "model.hpp"
36
37namespace ghost
38{
63 {
64 template<typename ModelBuilderType> friend class Solver;
65
66 Model build_model();
67
68 protected:
69 std::vector<Variable> variables;
70 std::vector<std::shared_ptr<Constraint>> constraints;
71 std::shared_ptr<Objective> objective;
72 std::shared_ptr<AuxiliaryData> auxiliary_data;
74
75 public:
82
84 virtual ~ModelBuilder() = default;
85
106 virtual void declare_variables() = 0;
107
120 virtual void declare_constraints();
121
133 virtual void declare_objective();
134
146
155 void create_n_variables( int number, const std::vector<int>& domain, int index = 0 );
156
167 void create_n_variables( int number, int starting_value, std::size_t size, int index = 0 );
168
173 inline int get_number_variables() { return static_cast<int>( variables.size() ); }
174
175 /*
176 * Inline method returning the number of declared constraints.
177 */
178 inline int get_number_constraints() { return static_cast<int>( constraints.size() ); }
179 };
180}
Definition model_builder.hpp:63
std::shared_ptr< Objective > objective
The shared pointer of the objective function of the problem instance. Is set to nullptr is declare_ob...
Definition model_builder.hpp:71
void create_n_variables(int number, const std::vector< int > &domain, int index=0)
virtual void declare_auxiliary_data()
int get_number_variables()
Definition model_builder.hpp:173
void create_n_variables(int number, int starting_value, std::size_t size, int index=0)
std::vector< Variable > variables
The global vector containing all variables of the problem instance.
Definition model_builder.hpp:69
virtual void declare_variables()=0
int get_number_constraints()
Definition model_builder.hpp:178
bool permutation_problem
Definition model_builder.hpp:73
ModelBuilder(bool permutation_problem=false)
std::vector< std::shared_ptr< Constraint > > constraints
The vector of shared pointers of each constraint composing the problem instance.
Definition model_builder.hpp:70
virtual void declare_objective()
virtual void declare_constraints()
std::shared_ptr< AuxiliaryData > auxiliary_data
The shared pointer of the auxiliary data of the problem instance. Is set to nullptr is declare_auxili...
Definition model_builder.hpp:72
virtual ~ModelBuilder()=default
Default virtual destructor.
Definition solver.hpp:119
Definition auxiliary_data.hpp:38