1 /*===========================================================================* 2 * This file is part of the Abstract Library for Parallel Search (ALPS). * 3 * * 4 * ALPS is distributed under the Eclipse Public License as part of the * 5 * COIN-OR repository (http://www.coin-or.org). * 6 * * 7 * Authors: * 8 * * 9 * Yan Xu, Lehigh University * 10 * Aykut Bulut, Lehigh University * 11 * Ted Ralphs, Lehigh University * 12 * * 13 * Conceptual Design: * 14 * * 15 * Yan Xu, Lehigh University * 16 * Ted Ralphs, Lehigh University * 17 * Laszlo Ladanyi, IBM T.J. Watson Research Center * 18 * Matthew Saltzman, Clemson University * 19 * * 20 * * 21 * Copyright (C) 2001-2019, Lehigh University, Yan Xu, Aykut Bulut, and * 22 * Ted Ralphs. * 23 * All Rights Reserved. * 24 *===========================================================================*/ 25 26 27 #ifndef AbcSolution_h 28 #define AbcSolution_h 29 30 #include "AlpsSolution.h" 31 32 #include "AbcModel.h" 33 34 #include <algorithm> 35 36 /** This class holds a MIP feasible primal solution. */ 37 class AbcSolution : public AlpsSolution { 38 private: 39 int size_; 40 double* value_; 41 double objective_; 42 43 public: AbcSolution()44 AbcSolution() 45 : 46 size_(0), 47 value_(0), 48 objective_() 49 {} AbcSolution(const int s,const double * val,const double obj)50 AbcSolution(const int s, const double* val, const double obj) 51 : 52 size_(s) 53 { 54 if (size_ >= 0) { 55 value_ = new double [size_]; 56 memcpy(value_, val, sizeof(double) * size_); 57 } 58 } 59 ~AbcSolution()60 ~AbcSolution() { 61 if (value_ != 0) { 62 delete [] value_; 63 value_ = 0; 64 } 65 } 66 67 /** Get the objective value value */ getObjValue()68 double getObjValue() const { return objective_; } 69 setObj(double obj)70 void setObj(double obj) { objective_=obj; } 71 setValue(int size,double const * value)72 void setValue(int size, double const * value) { 73 if (value_) { 74 delete[] value_; 75 } 76 size_ = size; 77 value_ = new double[size]; 78 std::copy(value, value+size, value_); 79 } 80 getQuality()81 virtual double getQuality() const { return getObjValue(); } 82 83 /** Get the size of the solution */ getSize()84 int getSize() const { return size_; } 85 86 /** Get the column solution */ getColSolution()87 const double* getColSolution() const 88 { return value_; } 89 90 /** Get item i in the solution vector */ getColSolution(int i)91 double getColSolution(int i) const { return value_[i]; } 92 93 /** Print out the solution.*/ 94 virtual void print(std::ostream& os) const; 95 96 using AlpsSolution::encode; 97 /** The method that encodes the solution into a encoded object. */ 98 virtual AlpsReturnStatus encode(AlpsEncoded * encoded) const; 99 decodeToSelf(AlpsEncoded & encoded)100 virtual AlpsReturnStatus decodeToSelf(AlpsEncoded & encoded) { 101 std::cerr << "Not implemented!" << std::endl; 102 throw std::exception(); 103 } 104 /** The method that decodes the solution from a encoded object. */ 105 virtual AlpsKnowledge * decode(AlpsEncoded &) const; 106 }; 107 108 #endif 109