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