Scippy

SCIP

Solving Constraint Integer Programs

prob_data_objectives.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program PolySCIP */
4 /* */
5 /* Copyright (C) 2012-2020 Konrad-Zuse-Zentrum */
6 /* fuer Informationstechnik Berlin */
7 /* */
8 /* PolySCIP is distributed under the terms of the ZIB Academic License. */
9 /* */
10 /* You should have received a copy of the ZIB Academic License */
11 /* along with PolySCIP; see the file LICENCE. */
12 /* */
13 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
14 
15 /**
16  * @file prob_data_objectives.h
17  * @brief Class storing multiple objectives of given problem instance
18  * @author Sebastian Schenker
19  *
20  */
21 
22 #ifndef POLYSCIP_SRC_PROB_DATA_OBJECTIVES_H_INCLUDED
23 #define POLYSCIP_SRC_PROB_DATA_OBJECTIVES_H_INCLUDED
24 
25 #include <cstdlib>
26 #include <stack>
27 #include <string>
28 #include <unordered_map>
29 #include <vector>
30 
31 #include "objscip/objscip.h"
32 #include "polyscip_types.h"
33 #include "scip/def.h"
34 
35 /**
36  * @class ProbDataObjectives
37  * @brief Stores coefficients and basic methods for objectives of given multi-objective problem
38  * @details In order to store the coefficients of our multi-objective problem we use specialisation of SCIP's ObjProbData
39  */
41 public:
42 
43  /**
44  * (Virtual) Destructor
45  */
46  virtual ~ProbDataObjectives() {};
47 
48  /**
49  * Number of objectives
50  * @return Number of objectives
51  */
52  std::size_t getNoObjs() const {return non_ignored_objs_.size();};
53 
54  /**
55  * Add identifier of objective
56  * @param name Objective identifier
57  */
58  void addObjName(const char* name);
59 
60  /**
61  * Add objective coefficient
62  * @param var Corresponding variable
63  * @param obj_name Corresponding objective identifier
64  * @param val Corresponding coefficient
65  */
66  void addObjCoeff(SCIP_VAR* var,
67  const char* obj_name,
69 
70  /**
71  * Get objective coefficient
72  * @param var Corresponding variable
73  * @param obj_no Corresponding number of objective
74  * @todo Const qualification
75  */
77  std::size_t obj_no);
78 
79  /**
80  * Scalar product of given weight and objectives w.r.t. given variable;
81  * if given variable is unknown, return 0.0 (since var can only have zero objective
82  * coefficients in given problem)
83  * @param var Corresponding variable
84  * @param weight Corresponding weight vector
85  * @todo Const qualification
86  */
88  const polyscip::WeightType& weight);
89 
90  /**
91  * Product of given solution value and objective coefficient w.r.t. given
92  * variable and objective number
93  * @param var Corresponding variable
94  * @param obj_no Corresponding objective number
95  * @param sol_val Corresponding solution value
96  * @todo Const qualification
97  */
99  std::size_t obj_no,
100  polyscip::ValueType sol_val);
101 
102  /**
103  * Variables corresponding to non-zero objective coefficients
104  * @param obj_no Corresponding objective number
105  */
106  std::vector<SCIP_VAR*> getNonZeroCoeffVars(std::size_t obj_no) const;
107 
108  /**
109  * Negate all objective coefficients of all variables in all objectives
110  */
111  void negateAllCoeffs();
112 
113  /**
114  * Number of non-zero coefficients of objective
115  * @param obj_no Corresponding objective number
116  */
117  std::size_t getNumberNonzeroCoeffs(std::size_t obj_no) const;
118 
119  /**
120  * Ignore two objectives
121  * @param obj_1 First objective to ignore
122  * @param obj_2 Second objective to ignore
123  */
124  void ignoreObjectives(std::size_t obj_1,
125  std::size_t obj_2);
126 
127  /**
128  * Unignore latest two objectives that were ignored previously
129  */
130  void unignoreObjectives();
131 
132  /**
133  * SCIP function for releasing memory
134  * @param scip Corresponding SCIP pointer
135  */
137 
138 private:
139 
140  std::unordered_map<std::string, std::size_t> name_to_no_; ///< maps objective identifier to objective number
141  std::unordered_map<SCIP_VAR*, polyscip::OutcomeType> var_to_coeffs_; ///< maps SCIP variable to objective coefficients
142  std::unordered_map<std::string, std::vector<SCIP_VAR*>> name_to_nonzero_coeffs_; ///< maps objective identifer to non-zero variables
143  std::vector<std::string> no_to_name_; ///< maps objective number to objective identifier
144  std::vector<std::size_t> non_ignored_objs_; ///< objective indices to be considered
145  std::stack<std::size_t> ignored_obj_; ///< objective indices to be ignored
146 
147 };
148 
149 #endif //POLYSCIP_SRC_PROB_DATA_OBJECTIVES_H_INCLUDED
std::vector< ValueType > WeightType
Type for weight vectors.
SCIP_Real ValueType
Type for computed values.
void addObjCoeff(SCIP_VAR *var, const char *obj_name, polyscip::ValueType val)
polyscip::ValueType getObjVal(SCIP_VAR *var, std::size_t obj_no, polyscip::ValueType sol_val)
void addObjName(const char *name)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
General types used for PolySCIP.
C++ wrapper for user problem data.
Definition: objprobdata.h:43
std::vector< SCIP_VAR * > getNonZeroCoeffVars(std::size_t obj_no) const
std::size_t getNumberNonzeroCoeffs(std::size_t obj_no) const
C++ wrapper classes for SCIP.
virtual SCIP_RETCODE scip_delorig(SCIP *scip)
void ignoreObjectives(std::size_t obj_1, std::size_t obj_2)
polyscip::ValueType getObjCoeff(SCIP_VAR *var, std::size_t obj_no)
Stores coefficients and basic methods for objectives of given multi-objective problem.
polyscip::ValueType getWeightedObjVal(SCIP_VAR *var, const polyscip::WeightType &weight)
common defines and data types used in all packages of SCIP
std::size_t getNoObjs() const