Optika GUI Toolik Version of the Day
test/gui/dependencyandexec/main.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #include "Teuchos_XMLParameterListHelpers.hpp"
00029 #include "Teuchos_VerboseObject.hpp"
00030 #include "Teuchos_FancyOStream.hpp"
00031 #include "Optika_GUI.hpp"
00032 
00033 void print(Teuchos::RCP<const Teuchos::ParameterList> theList){
00034   
00035   Teuchos::RCP<Teuchos::FancyOStream> out = 
00036     Teuchos::VerboseObjectBase::getDefaultOStream();
00037   writeParameterListToXmlOStream(*theList, *out);
00038 }
00039 
00040 namespace Optika{
00041 
00042 
00043 void RUN_OPTIKA_DEPENDENCY_AND_EXEC_TEST(){
00044  using Teuchos::FancyOStream;
00045  using Teuchos::VerboseObjectBase;
00046  using Teuchos::StringToIntegralParameterEntryValidator;
00047  using Teuchos::StringValidatorDependency;
00048  using Teuchos::ArrayNumberValidator;
00049  using Teuchos::StringVisualDependency;
00050  using Teuchos::NumberVisualDependency;
00051  using Teuchos::NumberArrayLengthDependency;
00052  using Teuchos::BoolValidatorDependency;
00053  using Teuchos::BoolVisualDependency;
00054  using Teuchos::SubtractionFunction;
00055  using Teuchos::RangeValidatorDependency;
00056  using Teuchos::tuple;
00057  using Teuchos::rcp;
00058 
00059 
00060  RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream();
00061  RCP<ParameterList> My_deplist = rcp(new ParameterList);
00062  RCP<DependencySheet> depSheet1 = rcp(new DependencySheet);
00063 
00064   RCP<StringToIntegralParameterEntryValidator<int> >
00065     stringFoodTypeValidator = rcp(
00066       new StringToIntegralParameterEntryValidator<int>(
00067         tuple<std::string>( "Cheese", "Soda", "Chips" )
00068         ,"Food Type"
00069         )
00070       );
00071 
00072   RCP<StringToIntegralParameterEntryValidator<int> >
00073     cheeseValidator = rcp(
00074       new StringToIntegralParameterEntryValidator<int>(
00075         tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" )
00076         ,"Food Selector"
00077         )
00078       );
00079   RCP<StringToIntegralParameterEntryValidator<int> >
00080     sodaValidator = rcp(
00081       new StringToIntegralParameterEntryValidator<int>(
00082         tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" )
00083         ,"Food Selector"
00084         )
00085       );
00086   RCP<StringToIntegralParameterEntryValidator<int> >
00087     chipsValidator = rcp(
00088       new StringToIntegralParameterEntryValidator<int>(
00089         tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" )
00090         ,"Food Selector"
00091         )
00092       );
00093 
00094   StringValidatorDependency::ValueToValidatorMap testValidatorMap1;
00095   testValidatorMap1["Cheese"] = cheeseValidator;
00096   testValidatorMap1["Soda"] = sodaValidator;
00097   testValidatorMap1["Chips"] = chipsValidator;
00098 
00099 
00100   ParameterList&
00101     stringValiDepList = My_deplist->sublist("String Validator Dependency", false, "String Validator Dependency testing list.\nWorking June 27th 2009");
00102   stringValiDepList.set("Food Selector", "Swiss", "select the food you want", cheeseValidator);
00103   stringValiDepList.set("Food Type", "Cheese", "String Validator Dependency Tester", stringFoodTypeValidator);
00104   depSheet1->addDependency(RCP<StringValidatorDependency>(
00105     new StringValidatorDependency(
00106     My_deplist->getEntryRCP("Food Type"),
00107     My_deplist->getEntryRCP("Food Selector"),
00108     testValidatorMap1 )));
00109  
00110 
00111   RCP<StringToIntegralParameterEntryValidator<int> >
00112     stringRangeValidator = rcp(
00113       new StringToIntegralParameterEntryValidator<int>(
00114         tuple<std::string>( "1-10", "10-33", "50-60" )
00115         ,"Range selector"
00116         )
00117       );
00118   ParameterList&
00119     stringValiDepList2 = My_deplist->sublist("String Validator Dependency (other validators)", false, "String Validator Dependency testing list for EnhancedNumber Validators.");
00120   stringValiDepList2.set("Range selector", "1-10", "selects the range to validate", stringRangeValidator);
00121   RCP<EnhancedNumberValidator<int> > range110Vali = 
00122     rcp(new EnhancedNumberValidator<int>(1,10));
00123   RCP<EnhancedNumberValidator<int> > range1033Vali = 
00124     rcp(new EnhancedNumberValidator<int>(10,33));
00125   RCP<EnhancedNumberValidator<int> > range5060Vali = 
00126     rcp(new EnhancedNumberValidator<int>(50,60));
00127   StringValidatorDependency::ValueToValidatorMap rangeValidatorMap1;
00128   rangeValidatorMap1["1-10"] = range110Vali;
00129   rangeValidatorMap1["10-33"] = range1033Vali;
00130   rangeValidatorMap1["50-60"] = range5060Vali;
00131   stringValiDepList2.set("RangeValue", 3, "the value of the range", range110Vali);
00132   depSheet1->addDependency(RCP<StringValidatorDependency>(
00133     new StringValidatorDependency(
00134   My_deplist->getEntryRCP("Range selector"),
00135   My_deplist->getEntryRCP("RangeValue"),
00136   rangeValidatorMap1)));
00137 
00138 
00139   ParameterList&
00140     boolValidatorDepList = My_deplist->sublist("Bool Validator Dependency List", false, "Bool Validator Dependency testing list.\nWorking June 27th 2009");
00141   boolValidatorDepList.set("Use Validator?", true, "truns the validator on and off");
00142   RCP<EnhancedNumberValidator<int> > basicVali = 
00143     rcp(new EnhancedNumberValidator<int>(1,10));
00144   boolValidatorDepList.set("do I have a validator?", 4, "does it have a validator?", basicVali);
00145   depSheet1->addDependency(RCP<BoolValidatorDependency>(
00146     new BoolValidatorDependency(
00147       My_deplist->getEntryRCP("Use Validator?"),
00148       My_deplist->getEntryRCP("do I have a validator?"),
00149       basicVali, 
00150       RCP<ParameterEntryValidator>())));
00151 
00152 
00153   RCP<StringToIntegralParameterEntryValidator<int> >
00154     lowTempCheeseValidator = rcp(
00155       new StringToIntegralParameterEntryValidator<int>(
00156         tuple<std::string>( "PepperJack", "Swiss", "American" )
00157         ,"Cheese to Fondue"
00158         )
00159       );
00160 
00161   RCP<StringToIntegralParameterEntryValidator<int> >
00162     highTempCheeseValidator = rcp(
00163       new StringToIntegralParameterEntryValidator<int>(
00164         tuple<std::string>( "Munster", "Provalone", "Kurtis Super Awesome Cheese")
00165         ,"Cheese to Fondue"
00166         )
00167       );
00168   ParameterList&
00169     rangeValidatorDepList = My_deplist->sublist("Range Validator and NumberVisual Dependency List", false, "Range Validator and Number Visual Dependency testing list.");
00170   rangeValidatorDepList.set("Temperature",101.0, "The temperature of the fondue");
00171   rangeValidatorDepList.set("Cheese to Fondue", "Swiss", "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator);
00172   RangeValidatorDependency<double>::RangeToValidatorMap tempranges;
00173   tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
00174   tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
00175   RCP<RangeValidatorDependency<double> > cheeseTempDep = rcp(
00176     new RangeValidatorDependency<double>(
00177       My_deplist->getEntryRCP("Temperature"),
00178       My_deplist->getEntryRCP("Cheese to Fondue"),
00179       tempranges));
00180  
00181   depSheet1->addDependency(cheeseTempDep);
00182   
00183   RCP<SubtractionFunction<double> > fondueFunc = rcp(
00184     new SubtractionFunction<double>(100));
00185   RCP<NumberVisualDependency<double> > fondueDep = 
00186       RCP<NumberVisualDependency<double> >(new NumberVisualDependency<double>(
00187       My_deplist->getEntryRCP("Temperature"),
00188       My_deplist->getEntryRCP("Cheese to Fondue"),
00189       true,
00190       fondueFunc));
00191   depSheet1->addDependency(fondueDep);
00192 
00193   ParameterList&
00194     numberArrayLengthDepList = My_deplist->sublist("Number Array Length Dependency List", false, "Number Array Length ependecy testing list.");
00195   numberArrayLengthDepList.set("Array Length", 8, "array length setter");
00196   Array<double> variableLengthArray(10,23.0);
00197   RCP<EnhancedNumberValidator<double> > varLengthArrayVali = RCP<EnhancedNumberValidator<double> >(
00198     new EnhancedNumberValidator<double>(10,50,4) );
00199   numberArrayLengthDepList.set("Variable Length Array", variableLengthArray, "variable length array",
00200   RCP<ArrayNumberValidator<double> >(new ArrayNumberValidator<double>(varLengthArrayVali)));
00201 
00202   RCP<NumberArrayLengthDependency<int, double> > arrayLengthDep(
00203     new NumberArrayLengthDependency<int, double>(My_deplist->getEntryRCP("Array Length"), 
00204     My_deplist->getEntryRCP("Variable Length Array")));
00205   depSheet1->addDependency(arrayLengthDep);
00206 
00207 
00208 
00209   ParameterList&
00210     numberValiAspDepList = My_deplist->sublist("Number Validator Aspect Dependency List", false, "Number Validator Aspect Dependency testing list.");
00211   RCP<EnhancedNumberValidator<int> > intVali2 = 
00212     rcp(new EnhancedNumberValidator<int>(0,20));
00213   numberValiAspDepList.set("Int", 8, "Int tester", intVali2);
00214   numberValiAspDepList.set("Int2", 8, "int2 tester", intVali2);
00215   numberValiAspDepList.set("Int dependee", 1, "Int dependee");
00216 
00217   ParameterList&
00218     boolVisDepList = My_deplist->sublist("Bool Visual Dependency List", false, "Bool Visual Dependency testing list.");
00219   boolVisDepList.set("ShowPrecs", true, "Whether or not to should the Preciondtioner list");
00220   ParameterList&
00221     Prec_List0 = boolVisDepList.sublist("Preconditioner",false,"Sublist that defines the preconditioner.");
00222   Prec_List0.set("Type", "ILU", "The tpye of preconditioner to use");
00223   RCP<EnhancedNumberValidator<double> > droptolValidator = rcp(new EnhancedNumberValidator<double>(0,10,1e-3));
00224   Prec_List0.set("Drop Tolerance", 1e-3
00225                 ,"The tolerance below which entries from the\n""factorization are left out of the factors.", droptolValidator);
00226   RCP<BoolVisualDependency> precDep1 = rcp(new BoolVisualDependency(
00227   My_deplist->getEntryRCP("ShowPrecs"),
00228   My_deplist->getEntryRCP("Preconditioner"),
00229   true));
00230   depSheet1->addDependency(precDep1);
00231 
00232 
00233 
00234 
00235 ParameterList&
00236     stringVisDepList = My_deplist->sublist("String Visual Dependency List", false, "String Visual Dependency testing list.\nWorking June 29 2009");
00237   RCP<StringToIntegralParameterEntryValidator<int> >
00238     favCheeseValidator = rcp(
00239       new StringToIntegralParameterEntryValidator<int>(
00240         tuple<std::string>( "Swiss", "American", "Cheder" )
00241         ,"Favorite Cheese"
00242         )
00243       );
00244    
00245    stringVisDepList.set(
00246     "Favorite Cheese", "American", "Your favorite type of cheese", favCheeseValidator);
00247    RCP<EnhancedNumberValidator<int> > swissValidator = rcp(new EnhancedNumberValidator<int>(0,10));
00248    stringVisDepList.set("Swiss rating", 0, "How you rate swiss on a scale of 1 to 10", swissValidator);
00249    RCP<StringVisualDependency> swissDep1 = 
00250       RCP<StringVisualDependency>(new StringVisualDependency(
00251       My_deplist->getEntryRCP("Favorite Cheese"),
00252       My_deplist->getEntryRCP("Swiss rating"),
00253       "Swiss", 
00254       true));
00255    depSheet1->addDependency(swissDep1);
00256 
00257 
00258 
00259 
00260 
00261   RCP<SubtractionFunction<int> > intVisTester =
00262     rcp(new SubtractionFunction<int>(32));
00263   ParameterList&
00264     numberVisDepList = My_deplist->sublist(
00265       "Number Visual Dependency List", false, 
00266       "Number Visual Dependency testing list.");
00267   numberVisDepList.set("Ice", 50, "Ice stuff");
00268   numberVisDepList.set("Room Temp", 10, "Room temperature");
00269   RCP<NumberVisualDependency<int> > iceDep = 
00270       RCP<NumberVisualDependency<int> >(
00271         new NumberVisualDependency<int>(
00272       My_deplist->getEntryRCP("Room Temp"),
00273       My_deplist->getEntryRCP("Ice"),
00274       true,
00275       intVisTester));
00276   depSheet1->addDependency(iceDep);
00277 
00278 
00279 
00280 
00281   void (*myFunc)(RCP<const ParameterList>);
00282   myFunc = print;
00283   getInput(My_deplist, depSheet1, myFunc);
00284 
00285   std::cout << "Dep List: \n";
00286   writeParameterListToXmlOStream(*My_deplist, *out);
00287 
00288   std::cout << "Deps: \n";
00289   depSheet1->printDeps(std::cout);
00290 
00291 
00292 }
00293 
00294 
00295 }
00296 
00297 
00298 int main(){
00299   Optika::RUN_OPTIKA_DEPENDENCY_AND_EXEC_TEST();
00300   return 0;
00301 }
00302 
00303 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines