source: colin/trunk/colin/PointSet.h @ 5736

Revision 5736, 2.8 KB checked in by jdsiiro, 5 years ago (diff)
  • switching PointSet? get_point() & set_point() to use Anys
  • cleaning up colin_driver() and removing the old colin_main() function
Line 
1/*  _________________________________________________________________________
2*
3*  COLIN: A Common Optimization Library INterface
4*  Copyright (c) 2003, Sandia National Laboratories.
5*  This software is distributed under the GNU Lesser General Public License.
6*  For more information, see the README.html file in the top COLIN directory.
7*  _________________________________________________________________________
8*/
9
10#ifndef colin_PointSet_h
11#define colin_PointSet_h
12
13#include <colin/ResponseCache.h>
14#include <colin/ResponseCacheFactory.h>
15#include <list>
16
17namespace colin {
18
19class PointSet
20{
21public:
22
23   ///
24   PointSet()
25      : cache(NULL)
26   {}
27
28   ///
29   PointSet(ResponseCache* cache_)
30      : cache(cache_)
31   {}
32
33   ///
34   void add_point(ApplicationHandle problem, utilib::AnyFixedRef point)
35   {
36      colin::AppRequest req = problem->set_domain(point);
37      (*this)->insertResponse( problem->eval_mngr().perform_evaluation(req) );
38   }
39
40   ///
41   void get_point(ApplicationHandle problem, utilib::AnyFixedRef& point)
42   {
43      std::list<utilib::Any> points;
44      get_points(problem,points,1);
45      if ( points.empty() )
46         EXCEPTION_MNGR(std::runtime_error, "PointSet::get_point(): "
47                        "empty PointSet.");
48      point = points.front();
49   }
50
51   ///
52   template <class PointT>
53   void get_points( ApplicationHandle problem, std::list<PointT>& points,
54                    size_t num_points = 0 )
55   {
56   colin::AppRequest req = problem->set_domain(utilib::Any());
57   std::list<colin::AppResponse> responses;
58   (*this)->getResponses(req, responses, num_points);
59
60   points.clear();
61   std::list<colin::AppResponse>::iterator curr = responses.begin();
62   std::list<colin::AppResponse>::iterator end  = responses.end();
63   while (curr != end) {
64     points.push_back(PointT());
65     curr->get_domain( points.back(), problem.application() );
66     curr++;
67     }
68   }
69
70   ///
71   ResponseCache* operator->()
72   {
73      if ( cache == NULL )
74      {
75         cache = CacheFactory().create();
76         // If the default caching system is "No Cache", we still need
77         // to create a cache for the PointSet to work.  We will fall
78         // back to using a Local Cache.
79         if ( cache == NULL )
80            cache = CacheFactory().create("Local");
81      }
82      assert(cache != NULL);
83      return cache;
84   }
85
86private:
87
88   /// The cache that we are wrapping
89   /** NB: we are NOT reference-counting this right now.  In the future,
90    *  we should probably consider doing so.  Until then, we do not need
91    *  to worry about operator=() because we are not ever responsible
92    *  for deleting the underlying cache.  Of course, if someone else
93    *  *does* delete the cache, we will get to experience the wonderful
94    *  world of seg faults.
95    */
96   ResponseCache* cache;
97};
98
99} // namespace colin
100
101#endif // colin_PointSet_h
Note: See TracBrowser for help on using the repository browser.