coin-Bcp
BCP_solution.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef _BCP_SOLUTION_H
4 #define _BCP_SOLUTION_H
5 
6 #include "BCP_vector.hpp"
7 #include "BCP_var.hpp"
8 
9 // This file is fully docified.
10 
14 class BCP_solution {
15 public:
17  virtual ~BCP_solution() {}
19  virtual double objective_value() const = 0;
20 };
21 
22 //#############################################################################
23 
34 public:
38  double _objective;
48 public:
50  BCP_solution_generic(bool delvars = true) :
51  _objective(0), _delete_vars(delvars), _vars(), _values() {}
56  if (_delete_vars)
58  }
59 
61  inline virtual double objective_value() const { return _objective; }
62 
64  inline void set_objective_value(double v) { _objective = v; }
65 
67  void display() const;
68 
71  void add_entry(BCP_var* var, double value) {
72  _vars.push_back(var);
73  _values.push_back(value);
74  _objective += value * var->obj();
75  }
76 };
77 
78 #endif
virtual double objective_value() const =0
The method returning the objective value of the solution.
BCP_vec< BCP_var * > _vars
Vector of variables that are at nonzero level in the solution.
bool _delete_vars
An indicator to show whether the pointers in _vars should be deleted upon destruction or not...
BCP_vec< double > _values
Values of these variables in the solution.
void push_back(const_reference x)
Append x to the end of the vector.
void set_objective_value(double v)
Set the objective value of the solution.
double obj() const
Return the objective coefficient.
Definition: BCP_var.hpp:87
virtual ~BCP_solution_generic()
The destructor deletes the data members.
void add_entry(BCP_var *var, double value)
Append a variable and the corresponding value to the end of the appropriate vectors.
Abstract base class that defines members common to all types of variables.
Definition: BCP_var.hpp:28
virtual double objective_value() const
Return the objective value of the solution.
double _objective
The objective value of the solution.
void purge_ptr_vector(BCP_vec< T * > &pvec, typename BCP_vec< T * >::iterator first, typename BCP_vec< T * >::iterator last)
This function purges the entries [first,last) from the vector of pointers pvec.
Definition: BCP_vector.hpp:266
virtual ~BCP_solution()
The virtual destructor ensures that the correct destructor is invoked.
This class holds a MIP feasible primal solution.
BCP_solution_generic(bool delvars=true)
The default constructor creates a solution with zero objective value.
void display() const
Display the solution.
This is the abstract base class for a solution to a Mixed Integer Programming problem.