PaGMO  1.1.5
inventory.cpp
1 /*****************************************************************************
2  * Copyright (C) 2004-2015 The PaGMO development team, *
3  * Advanced Concepts Team (ACT), European Space Agency (ESA) *
4  * *
5  * https://github.com/esa/pagmo *
6  * *
7  * act@esa.int *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  *****************************************************************************/
24 
25 #include "../population.h"
26 #include "../rng.h"
27 #include "../types.h"
28 #include "base_stochastic.h"
29 #include "inventory.h"
30 
31 namespace pagmo { namespace problem {
32 
33 inventory::inventory(int weeks,int sample_size, unsigned int seed) : base_stochastic(weeks,seed),
34  m_weeks(weeks),m_sample_size(sample_size)
35 {
36  set_lb(0.0);
37  set_ub(200.0);
38 }
39 
41 {
42  return base_ptr(new inventory(*this));
43 }
44 
46 {
47  m_drng.seed(m_seed);
48  const double c=1.0,b=1.5,h=0.1;
49  double retval=0;
50 
51  for (size_t i = 0; i<m_sample_size; ++i) {
52  double I=0;
53  for (decision_vector::size_type j = 0; j<x.size(); ++j) {
54  double d = m_drng() * 100;
55  retval += c * x[j] + b * std::max<double>(d-I-x[j],0) + h * std::max<double>(I+x[j]-d,0);
56  I = std::max<double>(0, I + x[j] - d);
57  }
58  }
59  f[0] = retval / m_sample_size;
60 }
61 
63 
67 {
68  std::ostringstream oss;
69  oss << "\n\tWeeks: " << m_weeks << '\n';
70  oss << "\tSample Size: " << m_sample_size << '\n';
71  oss << "\tSeed: " << m_seed << '\n';
72  return oss.str();
73 }
74 
75 std::string inventory::get_name() const
76 {
77  return "Inventory";
78 }
79 
80 }} //namespaces
81 
82 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::inventory)
Root PaGMO namespace.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
Definition: problem/base.h:62
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
void objfun_impl(fitness_vector &, const decision_vector &) const
Objective function implementation.
Definition: inventory.cpp:45
rng_double m_drng
Random number generator for double-precision floating point values.
Stochastic Programming Test Problem: Inventory Model.
Definition: inventory.h:65
void set_lb(const decision_vector &)
Set lower bounds from pagmo::decision_vector.
unsigned int m_seed
Seed of the random number generator.
std::string get_name() const
Get problem's name.
Definition: inventory.cpp:75
void set_ub(const decision_vector &)
Set upper bounds from pagmo::decision_vector.
base_ptr clone() const
Clone method.
Definition: inventory.cpp:40
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
Base Stochastic Optimization Problem.
std::string human_readable_extra() const
Extra human readable info for the problem.
Definition: inventory.cpp:66
inventory(int weeks=4, int sample_size=10, unsigned int seed=0)
Constructor from weeks, sample size and random seed.
Definition: inventory.cpp:33