[FlopCpp] Re : Iterating over a solution variable and a domain.

johnfuller360 at hotmail.com johnfuller360 at hotmail.com
Fri Jan 11 08:18:26 EST 2008


 
As far as iterating through sparse values, here's what I've done
 
***
 
#ifndef _SUBSETACCESS_H#define _SUBSETACCESS_H
/*   Here I've adapted flopc::MP_subset to make element protected rather   than private, then inherit from it to access the stored indices*/
#include <flopc.hpp>using namespace flopc;
template <int dim>class SubsetAccess : public MP_subset<dim>{public:   typedef std::map<std::vector<int>, int>  IndexVectorMap;   const IndexVectorMap& getIndexVectorMap() const   { return MP_subset<dim>::elements; }
   void setVariableForSubset   (MP_variable& x, double the_value)   {      const IndexVectorMap& elements= getIndexVectorMap();      IndexVectorMap::const_iterator pos;      for (pos= elements.begin(); pos!= elements.end(); pos++)      {  const vector<int>& args= pos->first;         int arg_sz= args.size();         int i0= (arg_sz>0?args[0]:0);         int i1= (arg_sz>1?args[1]:0);         int i2= (arg_sz>2?args[2]:0);         int i3= (arg_sz>3?args[3]:0);         int i4= (arg_sz>4?args[4]:0);         int i5= (arg_sz>5?args[5]:0);         x.lowerLimit(i1,i2,i3,i4,i5)= the_value;         x.upperLimit(i1,i2,i3,i4,i5)= the_value;      }   }
   void setDataForSubset   (MP_data& d, double the_value)   {      const IndexVectorMap& elements= getIndexVectorMap();      IndexVectorMap::const_iterator pos;      for (pos= elements.begin(); pos!= elements.end(); pos++)      {  const vector<int>& args= pos->first;         int arg_sz= args.size();         int i0= (arg_sz>0?args[0]:0);         int i1= (arg_sz>1?args[1]:0);         int i2= (arg_sz>2?args[2]:0);         int i3= (arg_sz>3?args[3]:0);         int i4= (arg_sz>4?args[4]:0);         int i5= (arg_sz>5?args[5]:0);         d(i1,i2,i3,i4,i5)= the_value;      }   }
   SubsetAccess(const MP_subset<dim>& s) : MP_subset<dim>(s)   {}};
#endif
***
 
example use for a five-index subset:
   SubsetAccess<5> sa(indexing_subsets);   const SubsetAccess<5>::IndexVectorMap& elements= sa.getIndexVectorMap();   SubsetAccess<5>::IndexVectorMap::const_iterator pos;   for (pos= elements.begin(); pos!= elements.end(); pos++)   {  const vector<int>& args= pos->first;      int arg_sz= args.size();      int i1= (arg_sz>0?args[0]:0);      int i2= (arg_sz>1?args[1]:0); int i3= (arg_sz>2?args[2]:0);      int i4= (arg_sz>3?args[3]:0); int i5= (arg_sz>4?args[4]:0);#ifdef DENSEOBJ      double xval= x.level(i1,i2,i3,i4,i5);      double c= COST(i1,i2,i3,i4,i5);#else      double xval= x.level(indexing_subset(i1,i2,i3,i4,i5));      double c= COST(indexing_subset(i1,i2,i3,i4,i5));#endif
 
 
> Date: Fri, 11 Jan 2008 13:06:36 +0000> From: yoyovicks at yahoo.fr> To: Tim.Hultberg at eumetsat.int; flopcpp at list.coin-or.org> Subject: [FlopCpp] Re : Iterating over a solution variable and a domain.> > Hello Tim,> > Thanks for your answers.> I had noticed the display method but I don't want to display them. So, I had the idea deriving from Functor and using forall but it sounds quite complicated for a such necessary feature so I asked the question on this ml first.> > The context is the following:> I have an application written in C# that needs to solve an LP problem.> I want to use C++/CLI to create the model with FLOPC++ based on data coming from a Managed DataSet in C#.(this is ok so far).> Then solve it. (this is also ok).> Then I want to get back the solution from flopc++ into a managed dataset.(this is the problem.)> Therefore I need a way to enumerate the content of flopc++ variables and to populate the dataset. dimensions are in columns.> > I am using subsets and the variables are very sparses so I cannot iterate continuously using a for loop.> So, my only chance is to derive the functor class?> Do you have any example on how deriving the functor class, please?> > Thanks for you help.> YO.> > > ----- Message d'origine ----> De : Tim Hultberg <Tim.Hultberg at eumetsat.int>> À : flopcpp at list.coin-or.org; yoyovicks at yahoo.fr> Envoyé le : Mardi, 8 Janvier 2008, 18h34mn 19s> Objet : Re: [FlopCpp] Iterating over a solution variable and a domain.> > Some alternatives:> 1. The display method of MP_variable does exactly this. See the> examples.> 2. Generally sets are indexed from 0 to size()-1> 3. You might use forall to iterate over a domain, but then you will> have to derive a class from Functor. I can show you how to do this if you> want and give me the context.> > Cheers, Tim> > >>> yo yo <yoyovicks at yahoo.fr> 01/08/08 4:48 PM >>>> Hello,> > I am trying to use flopcpp, so far the modelling works OK. Now I would> like to dump the content of a solution variable. I cannot find any way> to iterate over a variable and its domain. How can I do? I do not know> the values of the index because they are generated automatically.> I would like to make a "for each" on my solution variables and write> the value (with index) to somewhere else. Is this possible?> > Thanks for your help.> YO.> > > > > > _____________________________________________________________________________ > Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo!> Mail http://mail.yahoo.fr> > _______________________________________________> FlopCpp mailing list> FlopCpp at list.coin-or.org> http://list.coin-or.org/mailman/listinfo/flopcpp> > > > > > > _____________________________________________________________________________ > Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr> > _______________________________________________> FlopCpp mailing list> FlopCpp at list.coin-or.org> http://list.coin-or.org/mailman/listinfo/flopcpp> > 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.coin-or.org/pipermail/flopcpp/attachments/20080111/be12055d/attachment.html 


More information about the FlopCpp mailing list