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