source: trunk/Alps/examples/Abc/AbcSolution.cpp @ 277

Last change on this file since 277 was 277, checked in by andreasw, 13 years ago

first working version with autotools

File size: 2.9 KB
Line 
1/*===========================================================================*
2 * This file is part of the Abstract Library for Parallel Search (ALPS).     *
3 *                                                                           *
4 * ALPS is distributed under the Common Public License as part of the        *
5 * COIN-OR repository (http://www.coin-or.org).                              *
6 *                                                                           *
7 * Authors: Yan Xu, SAS Institute Inc.                                       *
8 *          Ted Ralphs, Lehigh University                                    *
9 *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
10 *          Matthew Saltzman, Clemson University                             *
11 *                                                                           *
12 *                                                                           *
13 * Copyright (C) 2001-2004, International Business Machines                  *
14 * Corporation, Lehigh University, Yan Xu, Ted Ralphs, Matthew Salzman and   *
15 * others. All Rights Reserved.                                              *
16 *===========================================================================*/
17
18#include <iomanip>
19#include <iostream>
20#include <set>
21
22//#include "AlpsDataPool.h"
23#include "AbcModel.h"
24#include "AbcSolution.h"
25
26//#############################################################################
27
28void 
29AbcSolution::print(std::ostream& os) const
30{
31    os <<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
32
33    os << "-------------------------" <<std::endl;
34    for (int i = 0; i < size_; ++i) {
35        if (fabs(value_[i]) > 1.0e-7) {
36            os << std::setw(6) << i << " " << value_[i] << std::endl;
37        }
38    }
39    os << "-------------------------" <<std::endl;
40    os <<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
41
42}
43
44/** The method that encodes the node into a encoded object. */
45AlpsEncoded*
46AbcSolution::encode() const 
47{ 
48  //  AlpsEncoded* encoded = new AlpsEncoded(typeid(*this).name());
49  AlpsEncoded* encoded = new AlpsEncoded("ALPS_SOLUTION");
50 
51  encoded->writeRep(size_);     // Base operand of `->' has non-pointer type
52  encoded->writeRep(value_, size_);
53  encoded->writeRep(objective_);
54
55  return encoded; 
56}
57
58//#############################################################################
59
60/** The method that decodes the node from a encoded object. */
61// Note: write and read sequence MUST same!
62AlpsKnowledge* 
63AbcSolution::decode(AlpsEncoded& encoded) const 
64{ 
65  int s;
66  double obj;
67  double* val = 0;
68  encoded.readRep(s);       
69  encoded.readRep(val, s);        // s must immediately before sol
70  encoded.readRep(obj);
71  AbcSolution* sol = new AbcSolution(s, val, obj);
72
73  if (val != 0) {
74      delete [] val;
75      val = 0;
76  }
77 
78  return sol;
79}
80
81//#############################################################################
Note: See TracBrowser for help on using the repository browser.