Main Page   Class Hierarchy   Compound List   File List   Contact   Download   Symbolic Constraints   Examples  

row_constraint.cc

00001 #include<scil/global.h>
00002 #include<scil/row_constraint.h>
00003 #include<scil/var_obj.h>
00004 #include<scil/row.h>
00005 #include<cstdlib>
00006 #include<vector>
00007 #include<algorithm>
00008 
00009 using namespace SCIL;
00010 
00011 row_constraint::row_constraint(row& r, cons_sense s)
00012 {
00013   NZ.reserve(r.size());
00014 
00015   std::list<row_entry>::const_iterator it;
00016   for( it = r.begin(); it!=r.end(); it++ ){
00017     NZ.push_back( pair(it->Var, it->coeff) );
00018   }
00019 
00020   set_sense(s);
00021   set_rhs(rhs());
00022 }
00023 
00024 
00025 double row_constraint::rhs()
00026 {
00027   if( NZ[0].v==nil ) return -NZ[0].c;
00028   return 0;
00029 }
00030 
00031 
00032 double row_constraint::coeff(var_obj* v)
00033 {
00034   vector<pair>::iterator lb;
00035 
00036   // search first pair in NZ with variable greater or equal to v
00037   lb = std::lower_bound< vector<pair>::iterator >(NZ.begin(), NZ.end(), pair(var(v),0), compareByVar);
00038 
00039   // if there's such a pair and the variables agree with v, return associated coeff
00040   if((lb != NZ.end()) && (lb->v == var(v)))
00041     return lb->c;
00042 
00043   // else all pair have variable strict less than v or there is no pair with variable v
00044   // non-existence <--> pair with coefficient zero
00045   return 0;
00046 }
00047 
00048 void row_constraint::non_zero_entries(row& r)
00049 {
00050   for( int i=0; i<(int)NZ.size(); i++ ){
00051     if( NZ[i].v!=nil ) r+= row_entry( NZ[i].v, NZ[i].c );
00052   }
00053 }
00054 
Generated on Mon Mar 28 22:03:49 2011 for SCIL by  doxygen 1.6.3