MeshKit  1.0
ia_main_stub.cpp
Go to the documentation of this file.
00001 
00002 
00003 // main file for stubbed version of interval assignment
00004 #include <stdio.h>
00005 #include <iostream>
00006 #include <assert.h>
00007 #include <cmath>
00008 
00009 #include "IAInterface.hpp"  // from stubs
00010 #include "IAVariable.hpp" // from stubs
00011 
00012 MeshKit::IAInterface *new_ia_interface()
00013 {
00014   return new MeshKit::IAInterface;
00015 }
00016 
00017 void delete_ia_interface(MeshKit::IAInterface * iainterface)
00018 {
00019   delete iainterface;
00020 }
00021 
00022 bool check_solution_correctness( MeshKit::IAInterface *ia_interface, 
00023                                  std::vector< std::pair<int,int> > &correct_solution)
00024 {
00025   const bool verbose_output = true;
00026   const bool debug = false;
00027   bool all_correct = true;
00028   MeshKit::IAInterface::VariableVec::const_iterator b = ia_interface->variables_begin();
00029   MeshKit::IAInterface::VariableVec::const_iterator e = ia_interface->variables_end();
00030   MeshKit::IAInterface::VariableVec::const_iterator i = b;
00031   unsigned int c = 0;
00032   if (debug)
00033     std::cout << "Checking Solution Correctness" << std::endl;
00034   for ( ; i != e; ++i, ++c )
00035   {
00036     const MeshKit::IAVariable *v = *i;
00037     assert(v);
00038     const int x = v->get_solution();
00039     assert(c < correct_solution.size() );
00040     const int lo = correct_solution[c].first;
00041     const int hi = correct_solution[c].second;
00042     if (debug)
00043       std::cout << "Checking variable " << c << " solution " << x << " in " 
00044               << "[" << lo << "," << hi << "]?" << std::endl;
00045     if (x < lo)
00046     {
00047       if (verbose_output)
00048         std::cout << "ERROR: Variable " << c << " solution " << x << " BELOW " 
00049              << "[" << lo << "," << hi << "]" << std::endl;
00050       all_correct = false;
00051     }
00052     if (x > hi)
00053     {
00054       if (verbose_output)
00055         std::cout << "ERROR: Variable " << c << " solution " << x << " ABOVE " 
00056              << "[" << lo << "," << hi << "]" << std::endl;
00057       all_correct = false;
00058     }
00059   }
00060   if (debug)
00061     std::cout << "done checking solution correctness." << std::endl;
00062   return all_correct;
00063 }
00064 
00065 void set_decoupled_pairs(MeshKit::IAInterface *ia_interface, 
00066                                          int num_pairs, double goal1, double goal2,
00067                                          std::vector< std::pair<int,int> > &correct_solution)
00068 {
00069   // trivial 2-sided mapping problem
00070   // we can make multiple pairs, each pair is independent, 
00071   // and pair i (in 0..num_pairs-1) has sides with one curve each with goals
00072   // i+goal1 and i+goal2, 
00073   //
00074   // test scalability, relaxed nlp: 100,000 constraints in 1 second. milp: 40 variables in 1 second, grows exponentially!
00075   for (int i = 0; i<num_pairs; ++i)
00076   { 
00077     // goals x_{2i} = 2, x_{2i+1} = 2
00078     // x_{2i}, goal: i + goal1
00079     const double g1 = i + goal1;
00080     const double g2 = i + goal2;
00081     MeshKit::IAVariable *v1 = ia_interface->create_variable( NULL, MeshKit::SOFT, g1);
00082     MeshKit::IAVariable *v2 = ia_interface->create_variable( NULL, MeshKit::SOFT, g2);
00083     const double compromise = sqrt( g1 * g2 );
00084     double lo = floor(compromise); 
00085     if ( ( compromise - lo ) < 0.1 )
00086       --lo;
00087     if ( lo < 1. )
00088       lo = 1.;
00089     double hi = ceil(compromise);
00090     if ( (hi - compromise) < 0.1 )
00091       ++hi;
00092     correct_solution.push_back( std::make_pair( lo, hi ) );
00093     correct_solution.push_back( std::make_pair( lo, hi ) );
00094 
00095     // constrain x_{2i} - x_{2i+1} = 0
00096     MeshKit::IAInterface::IAVariableVec side1, side2;
00097     side1.push_back(v1);
00098     side2.push_back(v2);
00099     ia_interface->constrain_sum_equal(side1, side2);
00100   }
00101 }
00102 
00103 
00104 void set_mapping_chain( MeshKit::IAInterface *ia_interface, const int num_sides, 
00105                        const bool grow_goal_by_i,
00106                        const int goal_m1, const int goal_m2, 
00107                        const int num_curve_min, const int num_curve_max )
00108 {
00109   // test problem 3, sides with more than one variable, with random goals
00110   printf("constructing coupled test problem - mapping chain\n");
00111 //  srand(10234); // for scaling by curves
00112 // srand(6893498); // for scaling by faces when the other results in a bend
00113   MeshKit::IAInterface::IAVariableVec side1, side2;
00114   int num_vars = 0;
00115   for (int i = 0; i<num_sides; ++i)
00116   { 
00117     // move side2 to side1
00118     side2.swap( side1 );
00119     
00120     // create new side2
00121     side2.clear();
00122     assert( num_curve_min > 0 );
00123     int num_curves = num_curve_min;
00124     if ( num_curve_max > num_curve_min )
00125       num_curves += (rand() % (1 + num_curve_max - num_curve_min) ); 
00126     for (int j = 0; j < num_curves; j++)
00127     {
00128       int goal_intervals = (1 + (rand() % goal_m1)) * (1 + (rand() % goal_m2)); 
00129       if (grow_goal_by_i)
00130         goal_intervals += num_vars;
00131       MeshKit::IAVariable *v = ia_interface->create_variable( NULL, MeshKit::SOFT, goal_intervals);
00132       side2.push_back(v);
00133     }
00134     num_vars += num_curves;
00135     
00136     // if we have two non-trivial opposite sides, then constrain them to be equal
00137     if (side1.size() && side2.size())
00138     {
00139       ia_interface->constrain_sum_equal(side1, side2);
00140     }
00141     
00142     // add a sum-even constraint
00143     if (0 && i==0)
00144     {
00145       printf("sum-even side: %d", i);
00146       assert( side2.size() );
00147       ia_interface->constrain_sum_even(side2);
00148     }
00149     
00150     // todo: try some hard-sets and non-trivial rhs
00151   }
00152   printf("problem size: %d variables, %d equal constraints\n", num_vars, num_sides-1);
00153 
00154 }
00155 
00156 void set_mapping_face( MeshKit::IAInterface *ia_interface )
00157 {
00158   // test problem 3, sides with more than one variable, with random goals
00159   printf("constructing mapping face with several curves per side\n");
00160   srand(10234);
00161   MeshKit::IAInterface::IAVariableVec side1, side2; 
00162 
00163   int num_vars[] = {1, 2};
00164   int goals[] = {10, 100, 50};
00165 
00166   int num_curves = num_vars[0];
00167   for (int j = 0; j < num_curves; j++)
00168   {
00169     int goal_intervals = goals[j];
00170     MeshKit::IAVariable *v = ia_interface->create_variable( NULL, MeshKit::SOFT, goal_intervals);
00171     side1.push_back(v);
00172   }
00173 
00174   num_curves = num_vars[1];
00175   for (int j = 0; j < num_curves; j++)
00176   {
00177     int goal_intervals = goals[num_vars[0] + j];
00178     MeshKit::IAVariable *v = ia_interface->create_variable( NULL, MeshKit::SOFT, goal_intervals);
00179     side2.push_back(v);
00180   }
00181 
00182   
00183     // if we have two non-trivial opposite sides, then constrain them to be equal
00184     if (side1.size() && side2.size())
00185     {
00186       ia_interface->constrain_sum_equal(side1, side2);
00187     }
00188     
00189 }
00190 
00191 
00192 // sum-even constraints test problems
00193 /*
00194   // test problem 4, a simple sum-even constraint
00195   int num_surfaces = 12; // 12
00196   int num_curves_per_surface = 4; // 4
00197   int num_shared_curves = 1; // 2
00198   
00199   int num_curves = 0;
00200   for (int i = 0; i < num_surfaces; ++i)
00201   {
00202     // gather the indices for the sum-even constraint
00203     int start_curve = num_curves - num_shared_curves;
00204     if (start_curve < 0)
00205       start_curve = 0;
00206     std::vector<int>curve_indices;
00207     if (debugging)
00208       printf("%d sum-even:",i);
00209     for (int j = 0; j < num_curves_per_surface; ++j)
00210     {
00211       curve_indices.push_back(start_curve+j);
00212       if (debugging)
00213         printf(" %d",start_curve+j);
00214     }
00215     num_curves = start_curve + num_curves_per_surface;
00216     const int rhs = 0; // test 0, -1
00217     constrain_sum_even(curve_indices,rhs);
00218     if (debugging)
00219       printf(" =%d\n",rhs);
00220   }
00221   // assign random goals to the curves
00222   for (int i = (int) I.size(); i < num_curves; ++i )
00223   {
00224     double goal = 1 + ((double) (rand() % 59)) / 10.; // 1 to 6.9
00225     // force an odd sum for testing purposes
00226     //if (i==0)
00227     //  goal += 1.;
00228     I.push_back(goal);
00229   }
00230 */
00231 
00232 void set_mapping_side( MeshKit::IAInterface *ia_interface, 
00233                       unsigned int num_curves, MeshKit::IAInterface::IAVariableVec &side, std::vector<double> &goals )
00234 {
00235   // see set_mapping_face below for usage  
00236   int num_new_curves = (int) num_curves - (int) side.size(); 
00237   if (num_new_curves < 0)
00238     num_new_curves = 0;
00239   for (int j = 0; j < num_new_curves; j++)
00240   {
00241     double goal_intervals = 1.; // default
00242     if (j < (int) goals.size())
00243       goal_intervals = goals[j]; // use the passed in goals
00244     else
00245       goals.push_back(goal_intervals); // pass back the assigned goals
00246     MeshKit::IAVariable *v = ia_interface->create_variable( NULL, MeshKit::SOFT, goal_intervals);
00247     side.push_back(v);
00248   }
00249 }
00250 
00251 
00252 void set_mapping_face( MeshKit::IAInterface *ia_interface, 
00253                       unsigned int num_curves_1, MeshKit::IAInterface::IAVariableVec &side_1, std::vector<double> &goals_1,
00254                       unsigned int num_curves_2, MeshKit::IAInterface::IAVariableVec &side_2, std::vector<double> &goals_2) 
00255 {
00256   // create a mapping face, with num_curves_? one each side.
00257   // two uses, independent for each side:
00258   // 1. Use the passed-in goals to create and fill in the ia_variables (so they can be used in the other form)
00259   // 2. Use the passed-in ia_variables, so to get two faces sharing a side or part of a side
00260   // a third use is a blend: re-use some variables and create some new ones. 
00261   // Goals default to 1 if unspecified or not enough are passed in.
00262   
00263 //  printf("set mapping face with %u and %u opposite curves.\n", num_curves_1, num_curves_2);
00264 //  printf("side_1: re-using %lu variables and creating %lu new ones\n", side_1.size(), num_curves_1 - side_1.size());
00265 //  printf("side_2: re-using %lu variables and creating %lu new ones\n", side_2.size(), num_curves_2 - side_2.size());
00266   
00267   // MeshKit::IAInterface::IAVariableVec side1, side2; 
00268   
00269   set_mapping_side( ia_interface, num_curves_1, side_1, goals_1 );
00270   set_mapping_side( ia_interface, num_curves_2, side_2, goals_2 );
00271 
00272   // if we have two non-trivial opposite sides, then constrain them to be equal
00273   if (side_1.size() && side_2.size())
00274   {
00275     ia_interface->constrain_sum_equal(side_1, side_2);
00276   }
00277   
00278 }
00279 
00280 
00281 void set_half_integer(  MeshKit::IAInterface *ia_interface, int version)
00282 {
00283   MeshKit::IAInterface::IAVariableVec side_1, side_2;
00284   std::vector<double> goals_1, goals_2;
00285 
00286   switch (version) {
00287     // loop, pointed
00288     case 0:
00289     {
00290       const double g1 = 107; // the one-curve side
00291       const double g2 =  53.5; // the multi-curve looping side
00292       // gives 1/2-integer solution
00293       
00294       goals_1.push_back(g1);
00295       goals_2.push_back(g2);
00296       goals_2.push_back(g2);
00297       set_mapping_face(ia_interface, 1, side_1, goals_1, 2, side_2, goals_2);
00298 
00299       MeshKit::IAInterface::IAVariableVec first_side_1 = side_1;
00300       MeshKit::IAVariable *common_0 = side_2[0];
00301       MeshKit::IAVariable *common_1 = side_2[1];
00302    
00303       side_1.clear();
00304       side_2.clear();
00305       side_1.push_back(common_0);
00306       goals_2.clear();
00307       goals_2.push_back(g2);
00308       set_mapping_face(ia_interface, 1, side_1, goals_1, 1, side_2, goals_2);
00309       
00310       side_1.clear();
00311       goals_1.clear();
00312       goals_1.push_back(g2);
00313       set_mapping_face(ia_interface, 1, side_1, goals_1, 1, side_2, goals_2);
00314 
00315       side_2.clear();
00316       side_2.push_back(common_1);
00317       set_mapping_face(ia_interface, 1, side_1, goals_1, 1, side_2, goals_2);
00318       
00319       // need to have many replicates of the single side, in order to have its integer weight overcome the opposite half-integer weights
00320       // MeshKit::IAVariable *weight_me = side_1[0]; 
00321       for (int r = 0; r < 7; r++)
00322       {
00323         side_2.clear();
00324         goals_2.clear();
00325         goals_2.push_back(g1);
00326         set_mapping_face(ia_interface, 1, first_side_1, goals_1, 1, side_2, goals_2);
00327       }
00328 
00329     }
00330       break;
00331 
00332     // loop, flat with extra curve for slack
00333     case 1:
00334     {
00335       const double g1 = 107; // the one-curve side
00336       const double g2 =  52.5; // the multi-curve looping side
00337       const double g3 =  2; // the multi-curve looping side
00338 
00339       goals_1.push_back(g1);
00340       goals_2.push_back(g2);
00341       goals_2.push_back(g2);
00342       goals_2.push_back(g3); // the slack curve
00343       set_mapping_face(ia_interface, 1, side_1, goals_1, 3, side_2, goals_2);
00344       
00345       MeshKit::IAInterface::IAVariableVec first_side_1 = side_1;
00346       MeshKit::IAVariable *common_0 = side_2[0];
00347       MeshKit::IAVariable *common_1 = side_2[1];
00348       
00349       side_1.clear();
00350       side_2.clear();
00351       side_1.push_back(common_0);
00352       goals_2.clear();
00353       goals_2.push_back(g2); // 8, for a different test problem testing flattening leading to an unbounded solution
00354       set_mapping_face(ia_interface, 1, side_1, goals_1, 1, side_2, goals_2);
00355       
00356       side_1.clear();
00357       goals_1.clear();
00358       goals_1.push_back(g2); // 8
00359       set_mapping_face(ia_interface, 1, side_1, goals_1, 1, side_2, goals_2);
00360       
00361       side_2.clear();
00362       side_2.push_back(common_1);
00363       set_mapping_face(ia_interface, 1, side_1, goals_1, 1, side_2, goals_2);
00364       
00365       for (int r = 0; r < 7; r++)
00366       {
00367         side_2.clear();
00368         goals_2.clear();
00369         goals_2.push_back(g1);
00370         set_mapping_face(ia_interface, 1, first_side_1, goals_1, 1, side_2, goals_2);
00371       }
00372 
00373     }
00374       break;
00375       
00376       // loop, pointed, but two curves per side around the loop
00377     case 2:
00378     {
00379       const double g1 = 107; // the one-curve side
00380       const double g2 =  26.75; // the multi-curve looping side 
00381       // above set to 26.3, 70 replicates makes some 26 and some 27
00382       // using 700 replicates with 26.75 gives a 1/2-integer (26.6) solution
00383 
00384       goals_1.push_back(g1);
00385       goals_2.push_back(g2);
00386       goals_2.push_back(g2);
00387       goals_2.push_back(g2);
00388       goals_2.push_back(g2);
00389       set_mapping_face(ia_interface, 1, side_1, goals_1, 4, side_2, goals_2);
00390       
00391       MeshKit::IAInterface::IAVariableVec first_side_1 = side_1;
00392       MeshKit::IAVariable *common_0  = side_2[0];
00393       MeshKit::IAVariable *common_0a = side_2[1];
00394       MeshKit::IAVariable *common_1  = side_2[2];
00395       MeshKit::IAVariable *common_1a = side_2[3];
00396       
00397       side_1.clear();
00398       side_1.push_back(common_0);
00399       side_1.push_back(common_0a);
00400       side_2.clear();
00401       goals_2.clear();
00402       goals_2.push_back(g2);
00403       goals_2.push_back(g2);
00404       set_mapping_face(ia_interface, 2, side_1, goals_1, 2, side_2, goals_2);
00405       
00406       side_1.clear();
00407       goals_1.clear();
00408       goals_1.push_back(g2);
00409       goals_1.push_back(g2);
00410       set_mapping_face(ia_interface, 2, side_1, goals_1, 2, side_2, goals_2);
00411       
00412       side_2.clear();
00413       side_2.push_back(common_1);
00414       side_2.push_back(common_1a);
00415       set_mapping_face(ia_interface, 2, side_1, goals_1, 2, side_2, goals_2);
00416       
00417       for (int r = 0; r < 700; r++)
00418       {
00419         side_2.clear();
00420         goals_2.clear();
00421         goals_2.push_back(g1);
00422         set_mapping_face(ia_interface, 1, first_side_1, goals_1, 1, side_2, goals_2);
00423       }
00424 
00425     }
00426       break;
00427 
00428       // loop, flat with extra curve for slack, and two curves per side around the loop
00429     case 3:
00430     {
00431       const double g1 = 107; // the one-curve side
00432       const double g2 =  26.5; // the multi-curve looping side 
00433       const double g3 =  2; // the multi-curve looping side 
00434 
00435       goals_1.push_back(g1);
00436       goals_2.push_back(g2);
00437       goals_2.push_back(g2);
00438       goals_2.push_back(g2);
00439       goals_2.push_back(g2);
00440       goals_2.push_back(g3); // the slack curve
00441       set_mapping_face(ia_interface, 1, side_1, goals_1, 5, side_2, goals_2);
00442       // todo, fiddle with weights to get 1/2-integer solution
00443       
00444       MeshKit::IAInterface::IAVariableVec first_side_1 = side_1;
00445       MeshKit::IAVariable *common_0  = side_2[0];
00446       MeshKit::IAVariable *common_0a = side_2[1];
00447       MeshKit::IAVariable *common_1  = side_2[2];
00448       MeshKit::IAVariable *common_1a = side_2[3];
00449       
00450       side_1.clear();
00451       side_1.push_back(common_0);
00452       side_1.push_back(common_0a);
00453       side_2.clear();
00454       goals_2.clear();
00455       goals_2.push_back(g2);
00456       goals_2.push_back(g2);
00457       set_mapping_face(ia_interface, 2, side_1, goals_1, 2, side_2, goals_2);
00458       
00459       side_1.clear();
00460       goals_1.clear();
00461       goals_1.push_back(g2);
00462       goals_1.push_back(g2);
00463       set_mapping_face(ia_interface, 2, side_1, goals_1, 2, side_2, goals_2);
00464       
00465       side_2.clear();
00466       side_2.push_back(common_1);
00467       side_2.push_back(common_1a);
00468       set_mapping_face(ia_interface, 2, side_1, goals_1, 2, side_2, goals_2);
00469 
00470       side_1 = first_side_1;
00471       for (int r = 0; r < 0; r++) // no replicates needed to get 1/2 integer solution
00472       {
00473         side_2.clear();
00474         goals_2.clear();
00475         goals_2.push_back(g1);
00476         set_mapping_face(ia_interface, 1, first_side_1, goals_1, 1, side_2, goals_2);
00477       }
00478 
00479     }
00480       break;
00481 
00482     default:
00483       break;
00484   }
00485 }
00486 
00487 void test_half_integer()
00488 {
00489   // create interface
00490   MeshKit::IAInterface *ia_interface = new_ia_interface();
00491   
00492   for (int v=0; v<4; ++v) // 0 <= v < 4
00493   {
00494     ia_interface->destroy_data();
00495   
00496     // set up model
00497     set_half_integer(ia_interface, v);
00498     printf("test problem %d\n", v);
00499   
00500     // solve ia
00501     ia_interface->execute_this(); 
00502   }
00503   
00504   delete_ia_interface( ia_interface );
00505 }
00506 
00507 void test_scaling_by_curves()
00508 {
00509  
00510   int num_tests = 6;
00511   int num_curves = 1000;
00512   double factor = sqrt(10); // 10./3.;
00513 
00514   for (int i = 0; i < num_tests; ++i)
00515   {
00516     MeshKit::IAInterface *ia_interface = new_ia_interface();
00517     ia_interface->destroy_data();
00518 
00519 //    void set_mapping_chain( MeshKit::IAInterface *ia_interface, const int num_sides, 
00520 //                           const bool grow_goal_by_i,
00521 //                           const int goal_m1, const int goal_m2, 
00522 //                           const int num_curve_min, const int num_curve_max )
00523 
00524     set_mapping_chain( ia_interface, 2, false, 3, 15, num_curves, num_curves);
00525     ia_interface->execute_this(); 
00526     
00527     delete_ia_interface( ia_interface );
00528     num_curves *= factor;
00529   }
00530   
00531 }
00532 
00533 void test_map_skew()
00534 {
00535   MeshKit::IAInterface *ia_interface = new_ia_interface();
00536   ia_interface->destroy_data();
00537   
00538   std::vector< std::pair<int,int> > correct_solution;
00539   set_mapping_face(ia_interface);
00540   //  set_decoupled_pairs(ia_interface, 1, 3.2, 12.1, correct_solution);
00541   ia_interface->execute_this(); 
00542 }
00543 
00544 void test_one_pair()
00545 {
00546   MeshKit::IAInterface *ia_interface = new_ia_interface();
00547   ia_interface->destroy_data();
00548 
00549   std::vector< std::pair<int,int> > correct_solution;
00550   set_decoupled_pairs(ia_interface, 1, 10., 1000., correct_solution);
00551 //  set_decoupled_pairs(ia_interface, 1, 3.2, 12.1, correct_solution);
00552   ia_interface->execute_this(); 
00553   bool solution_correct = check_solution_correctness( ia_interface, correct_solution );
00554   assert( solution_correct );
00555 }
00556 
00557 void test_many_pairs()
00558 {
00559   MeshKit::IAInterface *ia_interface = new_ia_interface();
00560   ia_interface->destroy_data();
00561 
00562   std::vector< std::pair<int,int> > correct_solution;
00563   set_decoupled_pairs(ia_interface, 8, 3.2, 12.1, correct_solution);
00564   set_decoupled_pairs(ia_interface, 1, 3.2, 12.1, correct_solution);
00565   set_decoupled_pairs(ia_interface, 8, 7.7, 4.2, correct_solution);
00566   set_decoupled_pairs(ia_interface, 40, 1.1, 5.2, correct_solution);
00567   set_decoupled_pairs(ia_interface, 40, 1.6, 4.5, correct_solution);
00568   set_decoupled_pairs(ia_interface, 4, 1.5, 1.5, correct_solution);
00569   set_decoupled_pairs(ia_interface, 4, 1, 1, correct_solution);
00570   
00571   ia_interface->execute_this(); 
00572   
00573   bool solution_correct = check_solution_correctness( ia_interface, correct_solution );
00574   assert( solution_correct );
00575   
00576   delete_ia_interface( ia_interface );
00577 }
00578 
00579 void test_long_chain()
00580 {
00581   
00582   // test scalability: 20000 gives 20,000 constraints, 100,000 variables in 1 second relaxed solution
00583 //  set_mapping_chain(ia_interface, 16000, false, 3, 15, 2, 11);
00584   // IANLP paper: 160, 160*3.3333, 1600, 1600*3.3333, 
00585   int num_curves = 160;
00586   int num_factors = 5; // 0, 1, 2, 3, 4, 5, 6
00587   int srandseed[] = {10234, 6893498, 10234, 102, 102, 72346};
00588   //                 0       1       2      3      4      5
00589   for (int i = 0; i < num_factors; ++i)
00590   {
00591     MeshKit::IAInterface *ia_interface = new_ia_interface();
00592     ia_interface->destroy_data();
00593 
00594     //  srand(10234); // for scaling by curves
00595     // srand(6893498); // for scaling by faces when the other results in a bend
00596     srand( srandseed[i] );
00597     std::cout << " i = " << i << " seed = " << srandseed[i] << std::endl;
00598 
00599     set_mapping_chain(ia_interface, num_curves, false, 3, 15, 2, 11);
00600     // goal distribution is gaussian in [1, 32]
00601 
00602     ia_interface->execute_this(); 
00603   
00604     // bool solution_defined = check_solution( ia_interface );
00605 
00606     delete_ia_interface( ia_interface );
00607     
00608     num_curves *= sqrt(10.);
00609   }
00610 }
00611 
00612 
00613 void test_growing_chain()
00614 {
00615   // test problem 2
00616   // printf("constructing growing chain, coupled test problem\n");
00617   MeshKit::IAInterface *ia_interface = new_ia_interface();
00618   ia_interface->destroy_data();
00619   
00620   // goals are 1, 2, 3, 4, ... 16
00621   // one curve per side
00622   set_mapping_chain(ia_interface, 16, true, 1, 1, 1, 1);
00623 
00624   ia_interface->execute_this(); 
00625   
00626   // bool solution_defined = check_solution( ia_interface );
00627   
00628   delete_ia_interface( ia_interface );
00629 }
00630 
00631 void mapping_test() 
00632 {
00633   
00634   MeshKit::IAInterface *ia_interface = new_ia_interface();
00635   ia_interface->destroy_data();
00636   
00637   MeshKit::ModelEnt* me_curves[4] = {0,0,0,0};
00638   // stubbed
00639   me_curves[0] = new MeshKit::ModelEnt();
00640   me_curves[1] = new MeshKit::ModelEnt();
00641   me_curves[2] = new MeshKit::ModelEnt();
00642   me_curves[3] = new MeshKit::ModelEnt();
00643   // convert moab entity handles to ModelEnt* and place in me_curves... ask Tim how
00644   
00645   MeshKit::MEntVector side1, side2;
00646   side1.push_back(me_curves[0]); side2.push_back(me_curves[2]);
00647   ia_interface->constrain_sum_equal(ia_interface->make_constraint_group(side1), 
00648                                     ia_interface->make_constraint_group(side2));
00649   side1.clear(); side2.clear();
00650   side1.push_back(me_curves[1]); side2.push_back(me_curves[3]);
00651   ia_interface->constrain_sum_equal(ia_interface->make_constraint_group(side1), 
00652                                     ia_interface->make_constraint_group(side2));
00653   
00654   // if there are loops, and the loops have strictly less than 4 curves, then
00655   // ia_interface->constrain_sum_even( ia_interface->make_constraint_group(curves in loop) );
00656   
00657   ia_interface->execute_this(); 
00658   
00659   delete_ia_interface( ia_interface );
00660 }
00661 
00662 
00663 void paving_test() 
00664 {
00665   
00666   MeshKit::IAInterface *ia_interface = new_ia_interface();
00667   ia_interface->destroy_data();
00668     
00669   MeshKit::ModelEnt* me_curves[4] = {0,0,0,0};
00670   // stubbed
00671   me_curves[0] = new MeshKit::ModelEnt();
00672   me_curves[1] = new MeshKit::ModelEnt();
00673   me_curves[2] = new MeshKit::ModelEnt();
00674   me_curves[3] = new MeshKit::ModelEnt();
00675   // convert moab entity handles to ModelEnt* and place in me_curves... ask Tim how
00676   for (int i = 0; i < 4; ++i)
00677   {
00678     me_curves[i]->meshIntervalSize = 1.; 
00679     me_curves[i]->entMeasure = 6. + (i==0 ? 1 : 0); //force odd
00680     me_curves[i]->meshIntervals = me_curves[i]->entMeasure / me_curves[i]->meshIntervalSize;
00681   }
00682   
00683   MeshKit::MEntVector loop1;
00684   loop1.push_back(me_curves[0]); 
00685   loop1.push_back(me_curves[1]);
00686   loop1.push_back(me_curves[2]); 
00687   loop1.push_back(me_curves[3]);
00688   ia_interface->constrain_sum_even(ia_interface->make_constraint_group(loop1));
00689   
00690   ia_interface->execute_this(); 
00691   
00692   delete_ia_interface( ia_interface );
00693 }
00694 
00695 int main(int argv, char* argc[])
00696 {
00697   // stubbed  
00698   
00699   // 2013 solution for implicit non-one coefficients 
00700   test_half_integer();
00701   
00702   // 2013 solution for explicit sum-even's
00703   
00704   // For NLIA paper
00705 //  test_map_skew();
00706 //  test_scaling_by_curves();
00707 //     test_long_chain(); // ma27 has memory issues over 50,000 constraints
00708 
00709 //  test_one_pair();
00710   // test_many_pairs();
00711 //  test_growing_chain();
00712   
00713   //paving_test();
00714 
00715 /* 100 long chain test
00716   srand(9384757); // debug
00717   for (int i = 0; i < 100; ++i)
00718     test_long_chain();
00719 */
00720   
00721  // mapping_test();
00722 
00723   return 0;
00724 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines