Loading...
Searching...
No Matches
MKP_Instance.h
1//
2// Created by henri on 12/10/22.
3//
4
5#ifndef IDOL_MKP_INSTANCE_H
6#define IDOL_MKP_INSTANCE_H
7
8#include <vector>
9#include <string>
10
11namespace idol::Problems::MKP {
12 class Instance;
13 Instance read_instance(const std::string& t_filename);
14}
15
20protected:
21 std::vector<double> m_profits;
22 std::vector<double> m_weights;
23 std::vector<double> m_capacities;
24public:
25 Instance(unsigned int t_n_knapsacks, unsigned int t_n_items);
26
27 Instance(const Instance&) = default;
28 Instance(Instance&&) noexcept = default;
29
30 Instance& operator=(const Instance&) = default;
31 Instance& operator=(Instance&&) noexcept = default;
32
33 ~Instance() = default;
34 [[nodiscard]] unsigned int n_knapsacks() const { return m_capacities.size(); }
35 [[nodiscard]] unsigned int n_items() const { return m_profits.size(); }
36 [[nodiscard]] double profit(unsigned int t_item) const { return m_profits[t_item]; }
37 [[nodiscard]] double weight(unsigned int t_item) const { return m_weights[t_item]; }
38 [[nodiscard]] double capacity(unsigned int t_knapsack) const { return m_capacities[t_knapsack]; }
39
40 [[nodiscard]] const auto& profits() const { return m_profits; }
41 [[nodiscard]] const auto& weights() const { return m_weights; }
42 [[nodiscard]] const auto& capacities() const { return m_capacities; }
43
44 void set_profit(unsigned int t_item, double t_value) { m_profits[t_item] = t_value; }
45 void set_weight(unsigned int t_item, double t_value) { m_weights[t_item] = t_value; }
46 void set_capacity(unsigned int t_knapsack, double t_value) { m_capacities[t_knapsack] = t_value; }
47
48};
49
50#endif //IDOL_MKP_INSTANCE_H