MeshKit  1.0
IADataBuilder.cpp
Go to the documentation of this file.
00001 // IADataBulder.cpp
00002 // Interval Assignment for Meshkit
00003 
00004 #include "meshkit/IAData.hpp"
00005 #include "meshkit/IADataBuilder.hpp"
00006 
00007 namespace MeshKit 
00008 {
00009 
00010 int IADataBuilder::add_variable( const double goal )
00011 {
00012   assert(ia_data);
00013   int variable_index = (int) ia_data->I.size();
00014   ia_data->I.push_back(goal);
00015   return variable_index;
00016 }
00017   
00018 
00019 void IADataBuilder::constrain_sum_even(const std::vector<int> &curve_indices, const int rhs)
00020 {
00021   assert(ia_data);
00022   if (!curve_indices.size())
00023     return;
00024   ia_data->sumEvenConstraints.push_back( IAData::sumEvenConstraintRow() );
00025   ia_data->sumEvenConstraints.back().M.reserve(curve_indices.size());
00026   ia_data->sumEvenConstraints.back().rhs = rhs;
00027   for (unsigned int j = 0; j < curve_indices.size(); ++j)
00028   {
00029     ia_data->sumEvenConstraints.back().M.push_back( IAData::sparseEntry( curve_indices[j], 1. ) );
00030   }
00031   assert( ia_data->sumEvenConstraints.back().M.size() == curve_indices.size() );
00032 }
00033 
00034 void IADataBuilder::constrain_opposite_side_equal(const std::vector<int> &side_1, const std::vector<int> &side_2, 
00035                                            const int rhs )
00036 {
00037   assert(ia_data);
00038   const size_t num_curves = side_1.size() + side_2.size();
00039   if (!num_curves)
00040     return;
00041   ia_data->constraints.push_back( IAData::constraintRow() );
00042   ia_data->constraints.back().M.reserve( num_curves );
00043   ia_data->constraints.back().upperBound = rhs;
00044   ia_data->constraints.back().lowerBound = rhs;
00045   for (unsigned int j = 0; j < side_1.size(); ++j)
00046   {
00047     ia_data->constraints.back().M.push_back( IAData::sparseEntry( side_1[j], 1. ) );
00048   }
00049   for (unsigned int j = 0; j < side_2.size(); ++j)
00050   {
00051     ia_data->constraints.back().M.push_back( IAData::sparseEntry( side_2[j], -1. ) );
00052   }
00053   assert( ia_data->constraints.back().M.size() == num_curves );
00054 }
00055 
00056 } // namespace MeshKit 
00057 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines