[FlopCpp] Lookup in domains

Tim Hultberg Tim.Hultberg at eumetsat.int
Tue Jun 19 16:06:07 EDT 2007


If you want to use forall you must derive from Functor and override void operator()() const (for an example see below.

To get P.such_that(DP(idx,P) you could use the "projection" operator <<= 

MP_subset<1> SP(P);
MP_index p;
int idx = ...

SP(P) <<= DP(I,P).such_that(I==idx);

[unfortunately  SP(P) <<= DP(idx,P); is not possible (at least for now)]


Hope this helps,
                     Tim

class MyFunctor : public Functor {
public:
  MyFunctor(MP_data& v, MP_index& a, MP_index& b) : V(v), A(a), B(b)    
  { }
    
  void operator()() const {
    std::cout<<A.evaluate()<<"  "<<B.evaluate()<<"  "<<V(A.evaluate(),B.evaluate())<<std::endl;
  }
  
  MP_data& V;
  MP_index& A;
  MP_index& B;
};



int main() {
  MP_model::getDefaultModel().setSolver(new OsiClpSolverInterface);
  
  MP_set A(4);
  MP_set B(5);

  MP_data V(A,B);

  V(A,B) = A+B;

  MP_subset<2> AB(A,B);

  AB.insert(0,2);
  AB.insert(1,2);
  AB.insert(1,1);
  AB.insert(2,1);
  AB.insert(1,4);

  MP_index a,b;

  MyFunctor F(V,a,b);
  
  std::cout<<"1a ======>"<<std::endl;
  forall( AB(a,b), F);

  // For this to compile the copy constructor Functor(const Functor&); must be changed from private to protected  
  //  std::cout<<"1b ======>"<<std::endl;
  //  forall( AB(a,b), MyFunctor(V,a,b));

  // BUG the such_that is not considered !! (will try to correct it)
  std::cout<<"2 ======>"<<std::endl;
  forall( (AB(a,b).such_that(b==1)), F);

  MP_subset<1>  sB(B);

  sB(b) <<= AB(a,b).such_that(a==1);

  std::cout<<"3 ======>"<<std::endl;
  std::cout<<sB.size()<<std::endl;
  sB.display("sB");
}


Tim Hultberg

>>> "Berit Løfstedt" <berit at ange.dk> 06/19/07 3:34 PM >>>
Having build a model in flopc++ I now need to interpret the results of the
model. However, I find it hard to map variables back to domains.
Furthermore, I need to lookup in subsets according to a variables index in a
given domain.  (i.e. I have a subset DP(D,P) and I have the index for D=idx
- how do I get the P.such_that(DP(idx,P) returns me the indexes ?)

I have tried looking at forall and such_that defined for sets, but cannot
really make it work. Is there a functionality in flopcpp that I am
overlooking, which enables me to map a solution vector back to the domains
defining the variable?

I realise that I can simply iterate through the sets, but there is much
redundant work combined with this, when all i need is a reverse map from an
index(indices) to a domain.

Another request is references to good examples on the web on how to
interpret the results of the LP back to the domains, that defined them.


-- 
Best Regards,

Berit Løfstedt
berit at ange.dk
Ange Optimization




More information about the FlopCpp mailing list