Note that there are some explanatory texts on larger screens.

plurals
  1. POboost::multi_index_container with random_access and ordered_unique
    primarykey
    data
    text
    <p>I have a problem getting <code>boost::multi_index_container</code> work with random-access and with orderd_unique at the same time. (I'm sorry for the lengthly question, but I think I should use an example..)</p> <p>Here an example: Suppose I want to produce N objects in a factory and for each object I have a demand to fulfill (this demand is known at creation of the multi-index). Well, within my algorithm I get intermediate results, which I store in the following class:</p> <pre><code>class intermediate_result { private: std::vector&lt;int&gt; parts; // which parts are produced int used_time; // how long did it take to produce ValueType max_value; // how much is it worth }; </code></pre> <p>The vector <code>parts</code> descibes, which objects are produced (its length is N and it is lexicographically smaller then my coresp demand-vector!) - for each such vector I know the used_time as well. Additionally I get a value for this vector of produced objects.</p> <p>I got another constraint so that I can't produce every object - my algorithm needs to store several <code>intermediate_result</code>-objects in a data-structure. And here <code>boost::multi_index_container</code> is used, because the pair of <code>parts</code> and <code>used_time</code> describes a unique <code>intermediate_result</code> (and it should be unique in my data-structure) but the <code>max_value</code> is another index I'll have to consider, because my algorithm always needs the <code>intermediate_result</code> with the highest <code>max_value</code>.</p> <p>So I tried to use <code>boost::multi_index_container</code> with <code>ordered_unique&lt;&gt;</code> for my "parts&amp;used_time-pair" and <code>ordered_non_unique&lt;&gt;</code> for my <code>max_value</code> (different <code>intermediate_result</code>-objects may have the same value).</p> <p>The problem is: the predicate, which is needed to decide which "parts&amp;used_time-pair" is smaller, uses <code>std::lexicographical_compare</code> on my <code>parts</code>-vector and hence is very slow for many <code>intermediate_result</code>-objects. But there would be a solution: my demand for each object isn't that high, therefore I could store on each <strong>possible</strong> parts-vector the intermediate results uniquely by its <code>used_time</code>.</p> <p>For example: if I have a demand-vector <code>( 2 , 3 , 1)</code> then I need a data-structure which stores <code>(2+1)*(3+1)*(1+1)=24</code> possible parts-vectors and on each such entry the different used_times, which have to be unique! (storing the smallest time is insufficient - for example: if my additional constraint is: to meet a given time exactly for production)</p> <p>But how do I combine a <code>random_access&lt;&gt;</code>-index with an <code>ordered_unique&lt;&gt;</code>-index?<br> (<a href="http://www.boost.org/doc/libs/1_40_0/libs/multi_index/doc/examples.html#example11" rel="nofollow noreferrer">Example11</a> didn't help me on this one..)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload