00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream>
00019 #include <fstream>
00020 #include <string>
00021 #include <sstream>
00022 #include <cmath>
00023 #include <algorithm>
00024 #include <cstdlib>
00025 #include <stdexcept>
00026 #include <ctime>
00027 #include <exception>
00028
00029
00030
00031 #include "variables_information.h"
00032
00033
00034
00035 #include "../../parsers/tinyxml/tinyxml.h"
00036
00037 namespace OpenNN
00038 {
00039
00040
00041
00045
00046 VariablesInformation::VariablesInformation(void)
00047 {
00048 set();
00049 }
00050
00051
00052
00053
00059
00060 VariablesInformation::VariablesInformation(const unsigned int& new_variables_number)
00061 {
00062 set(new_variables_number);
00063 }
00064
00065
00066
00067
00073
00074 VariablesInformation::VariablesInformation(const unsigned int& new_inputs_number, const unsigned int& new_targets_number)
00075 {
00076 set(new_inputs_number, new_targets_number);
00077 }
00078
00079
00080
00084
00085 VariablesInformation::VariablesInformation(TiXmlElement* variables_information_element)
00086 {
00087 set(variables_information_element);
00088 }
00089
00090
00091
00092
00096
00097 VariablesInformation::VariablesInformation(const VariablesInformation& other_variables_information)
00098 {
00099 variables_number = other_variables_information.variables_number;
00100
00101
00102
00103 inputs_indices = other_variables_information.inputs_indices;
00104 targets_indices = other_variables_information.targets_indices;
00105
00106
00107
00108 names = other_variables_information.names;
00109 units = other_variables_information.units;
00110 descriptions = other_variables_information.descriptions;
00111
00112
00113
00114 display = other_variables_information.display;
00115 }
00116
00117
00118
00119
00121
00122 VariablesInformation::~VariablesInformation(void)
00123 {
00124 }
00125
00126
00127
00128
00132
00133 VariablesInformation& VariablesInformation::operator=(const VariablesInformation& other_variables_information)
00134 {
00135 if(this != &other_variables_information)
00136 {
00137 variables_number = other_variables_information.variables_number;
00138
00139
00140
00141 inputs_indices = other_variables_information.inputs_indices;
00142 targets_indices = other_variables_information.targets_indices;
00143
00144
00145
00146 names = other_variables_information.names;
00147 units = other_variables_information.units;
00148 descriptions = other_variables_information.descriptions;
00149
00150
00151
00152 display = other_variables_information.display;
00153 }
00154
00155 return(*this);
00156 }
00157
00158
00159
00160
00161
00162
00167
00168 bool VariablesInformation::operator == (const VariablesInformation& other_variables_information) const
00169 {
00170 if(variables_number == other_variables_information.variables_number
00171 && inputs_indices == other_variables_information.inputs_indices
00172 && targets_indices == other_variables_information.targets_indices
00173 && names == other_variables_information.names
00174 && units == other_variables_information.units
00175 && descriptions == other_variables_information.descriptions
00176 && display == other_variables_information.display)
00177 {
00178 return(true);
00179 }
00180 else
00181 {
00182 return(false);
00183 }
00184 }
00185
00186
00187
00188
00189
00190
00191
00193
00194 const Vector<unsigned int>& VariablesInformation::get_inputs_indices(void) const
00195 {
00196 return(inputs_indices);
00197 }
00198
00199
00200
00201
00203
00204 const Vector<unsigned int>& VariablesInformation::get_targets_indices(void) const
00205 {
00206 return(targets_indices);
00207 }
00208
00209
00210
00211
00213
00214 const Vector<std::string>& VariablesInformation::get_names(void) const
00215 {
00216 return(names);
00217 }
00218
00219
00220
00221
00224
00225 const std::string& VariablesInformation::get_name(const unsigned int& i) const
00226 {
00227
00228
00229 #ifdef _DEBUG
00230
00231 unsigned int variables_number = get_variables_number();
00232
00233 if(i >= variables_number)
00234 {
00235 std::ostringstream buffer;
00236
00237 buffer << "OpenNN Exception: VariablesInformation class.\n"
00238 << "std::string& get_name(unsigned int) method.\n"
00239 << "Index of variable must be less than number of variables.\n";
00240
00241 throw std::logic_error(buffer.str());
00242 }
00243
00244 #endif
00245
00246 return(names[i]);
00247 }
00248
00249
00250
00251
00253
00254 Vector<std::string> VariablesInformation::arrange_inputs_name(void) const
00255 {
00256 const unsigned int inputs_number = count_inputs_number();
00257
00258 Vector<std::string> inputs_name(inputs_number);
00259
00260 unsigned int index;
00261
00262 for(unsigned int i = 0; i < inputs_number; i++)
00263 {
00264 index = inputs_indices[i];
00265
00266 inputs_name[i] = names[index];
00267 }
00268
00269 return(inputs_name);
00270 }
00271
00272
00273
00274
00276
00277 Vector<std::string> VariablesInformation::arrange_targets_name(void) const
00278 {
00279 const unsigned int targets_number = count_targets_number();
00280
00281 Vector<std::string> targets_name(targets_number);
00282
00283 unsigned int index;
00284
00285 for(unsigned int i = 0; i < targets_number; i++)
00286 {
00287 index = targets_indices[i];
00288
00289 targets_name[i] = names[index];
00290 }
00291
00292 return(targets_name);
00293 }
00294
00295
00296
00297
00299
00300 const Vector<std::string>& VariablesInformation::get_units(void) const
00301 {
00302 return(units);
00303 }
00304
00305
00306
00307
00310
00311 const std::string& VariablesInformation::get_unit(const unsigned int& i) const
00312 {
00313
00314
00315 #ifdef _DEBUG
00316
00317 unsigned int variables_number = get_variables_number();
00318
00319 if(i >= variables_number)
00320 {
00321 std::ostringstream buffer;
00322
00323 buffer << "OpenNN Exception: VariablesInformation class.\n"
00324 << "const std::string& get_units(const unsigned int&) const method.\n"
00325 << "Index of variable must be less than number of variables.\n";
00326
00327 throw std::logic_error(buffer.str());
00328 }
00329
00330 #endif
00331
00332 return(units[i]);
00333 }
00334
00335
00336
00337
00339
00340 Vector<std::string> VariablesInformation::arrange_inputs_units(void) const
00341 {
00342 unsigned int variables_number = get_variables_number();
00343
00344 Vector<std::string> inputs_units;
00345
00346 if(units.size() == variables_number)
00347 {
00348 unsigned int inputs_number = count_inputs_number();
00349
00350 inputs_units.set(inputs_number);
00351 unsigned int index;
00352
00353 for(unsigned int i = 0; i < inputs_number; i++)
00354 {
00355 index = inputs_indices[i];
00356
00357 inputs_units[i] = units[index];
00358 }
00359 }
00360
00361 return(inputs_units);
00362 }
00363
00364
00365
00366
00368
00369 Vector<std::string> VariablesInformation::arrange_targets_units(void) const
00370 {
00371 const unsigned int variables_number = get_variables_number();
00372
00373 Vector<std::string> targets_units;
00374
00375 if(units.size() == variables_number)
00376 {
00377 const unsigned int targets_number = count_targets_number();
00378
00379 targets_units.set(targets_number);
00380 unsigned int index;
00381
00382 for(unsigned int i = 0; i < targets_number; i++)
00383 {
00384 index = targets_indices[i];
00385
00386 targets_units[i] = units[index];
00387 }
00388 }
00389
00390 return(targets_units);
00391 }
00392
00393
00394
00395
00397
00398 const Vector<std::string>& VariablesInformation::get_descriptions(void) const
00399 {
00400 return(descriptions);
00401 }
00402
00403
00404
00405
00408
00409 const std::string& VariablesInformation::get_description(const unsigned int& i) const
00410 {
00411
00412
00413 #ifdef _DEBUG
00414
00415 unsigned int variables_number = get_variables_number();
00416
00417 if(i >= variables_number)
00418 {
00419 std::ostringstream buffer;
00420
00421 buffer << "OpenNN Exception: VariablesInformation class.\n"
00422 << "const std::string& get_description(const unsigned int&) const method.\n"
00423 << "Index of variable must be less than number of variables.\n";
00424
00425 throw std::logic_error(buffer.str());
00426 }
00427
00428 #endif
00429
00430 return(descriptions[i]);
00431 }
00432
00433
00434
00435
00437
00438 Vector<std::string> VariablesInformation::arrange_inputs_description(void) const
00439 {
00440 const unsigned int variables_number = get_variables_number();
00441
00442 Vector<std::string> inputs_description;
00443
00444 if(units.size() == variables_number)
00445 {
00446 const unsigned int inputs_number = count_inputs_number();
00447 inputs_description.set(inputs_number);
00448 unsigned int index;
00449
00450 for(unsigned int i = 0; i < inputs_number; i++)
00451 {
00452 index = inputs_indices[i];
00453
00454 inputs_description[i] = descriptions[index];
00455 }
00456 }
00457
00458 return(inputs_description);
00459 }
00460
00461
00462
00463
00465
00466 Vector<std::string> VariablesInformation::arrange_targets_description(void) const
00467 {
00468 unsigned int variables_number = get_variables_number();
00469
00470 Vector<std::string> target_descriptions;
00471
00472 if(descriptions.size() == variables_number)
00473 {
00474 unsigned int targets_number = count_targets_number();
00475
00476 target_descriptions.set(targets_number);
00477 unsigned int index;
00478
00479 for(unsigned int i = 0; i < targets_number; i++)
00480 {
00481 index = targets_indices[i];
00482
00483 target_descriptions[i] = descriptions[index];
00484 }
00485 }
00486
00487 return(target_descriptions);
00488 }
00489
00490
00491
00492
00504
00505 Vector< Vector<std::string> > VariablesInformation::arrange_inputs_targets_information(void) const
00506 {
00507 unsigned int variable_index;
00508
00509 unsigned int variables_number = get_variables_number();
00510
00511 unsigned int inputs_number = count_inputs_number();
00512
00513 Vector<std::string> inputs_name;
00514 Vector<std::string> inputs_units;
00515 Vector<std::string> inputs_description;
00516
00517 for(unsigned int i = 0; i < inputs_number; i++)
00518 {
00519 variable_index = inputs_indices[i];
00520
00521 if(names.size() == variables_number)
00522 {
00523 inputs_name.set(inputs_number);
00524 inputs_name[i] = names[variable_index];
00525 }
00526
00527 if(units.size() == variables_number)
00528 {
00529 inputs_units.set(inputs_number);
00530 inputs_units[i] = units[variable_index];
00531 }
00532
00533 if(descriptions.size() == variables_number)
00534 {
00535 inputs_description.set(inputs_number);
00536 inputs_description[i] = descriptions[variable_index];
00537 }
00538 }
00539
00540 unsigned int targets_number = count_targets_number();
00541
00542 Vector<std::string> targets_name;
00543 Vector<std::string> targets_units;
00544 Vector<std::string> target_descriptions;
00545
00546 for(unsigned int i = 0; i < targets_number; i++)
00547 {
00548 variable_index = targets_indices[i];
00549
00550 if(names.size() == variables_number)
00551 {
00552 targets_name.set(targets_number);
00553 targets_name[i] = names[variable_index];
00554 }
00555
00556 if(units.size() == variables_number)
00557 {
00558 targets_units.set(targets_number);
00559 targets_units[i] = units[variable_index];
00560 }
00561
00562 if(descriptions.size() == variables_number)
00563 {
00564 target_descriptions.set(targets_number);
00565 target_descriptions[i] = descriptions[variable_index];
00566 }
00567 }
00568
00569 Vector< Vector<std::string> > variables_information(6);
00570
00571 variables_information[0] = inputs_name;
00572 variables_information[1] = inputs_units;
00573 variables_information[2] = inputs_description;
00574
00575 variables_information[3] = targets_name;
00576 variables_information[4] = targets_units;
00577 variables_information[5] = target_descriptions;
00578
00579 return(variables_information);
00580 }
00581
00582
00583
00584
00587
00588 const bool& VariablesInformation::get_display(void) const
00589 {
00590 return(display);
00591 }
00592
00593
00594
00595
00597
00598 void VariablesInformation::set(void)
00599 {
00600 set_variables_number(0);
00601
00602 display = true;
00603 }
00604
00605
00606
00607
00611
00612 void VariablesInformation::set(const unsigned int& new_variables_number)
00613 {
00614 set_variables_number(new_variables_number);
00615
00616 display = true;
00617 }
00618
00619
00620
00621
00627
00628 void VariablesInformation::set(const unsigned int& inputs_number, const unsigned int& targets_number)
00629 {
00630 set_variables_number(inputs_number+targets_number);
00631
00632 inputs_indices.set(inputs_number);
00633 inputs_indices.initialize_sequential();
00634
00635 targets_indices.set(targets_number);
00636 targets_indices.initialize_sequential();
00637 targets_indices += inputs_number;
00638 }
00639
00640
00641
00642
00645
00646 void VariablesInformation::set(TiXmlElement* variables_information_element)
00647 {
00648 from_XML(variables_information_element);
00649 }
00650
00651
00652
00653
00658
00659 void VariablesInformation::set_inputs_indices(const Vector<unsigned int>& new_inputs_indices)
00660 {
00661 inputs_indices = new_inputs_indices;
00662 }
00663
00664
00665
00666
00671
00672 void VariablesInformation::set_targets_indices(const Vector<unsigned int>& new_targets_indices)
00673 {
00674 targets_indices = new_targets_indices;
00675 }
00676
00677
00678
00679
00681
00682 void VariablesInformation::set_input(void)
00683 {
00684 unsigned int variables_number = get_variables_number();
00685
00686 inputs_indices.set(0, 1, variables_number-1);
00687 }
00688
00689
00690
00691
00693
00694 void VariablesInformation::set_target(void)
00695 {
00696 unsigned int variables_number = get_variables_number();
00697
00698 targets_indices.set(0, 1, variables_number-1);
00699 }
00700
00701
00702
00703
00709
00710 void VariablesInformation::set_default_indices(void)
00711 {
00712 unsigned int variables_number = get_variables_number();
00713
00714 inputs_indices.set(variables_number-1);
00715 inputs_indices.initialize_sequential();
00716
00717 targets_indices.set(1, variables_number-1);
00718 }
00719
00720
00721
00722
00726
00727 void VariablesInformation::set_names(const Vector<std::string>& new_names)
00728 {
00729
00730
00731 #ifdef _DEBUG
00732
00733 unsigned int variables_number = get_variables_number();
00734
00735 unsigned int size = new_names.size();
00736
00737 if(size != variables_number)
00738 {
00739 std::ostringstream buffer;
00740
00741 buffer << "OpenNN Exception: VariablesInformation class.\n"
00742 << "void set_names(const Vector<std::string>&) method.\n"
00743 << "Size must be equal to number of variables.\n";
00744
00745 throw std::logic_error(buffer.str());
00746 }
00747
00748 #endif
00749
00750 names = new_names;
00751 }
00752
00753
00754
00755
00760
00761 void VariablesInformation::set_name(const unsigned int& i, const std::string& new_name)
00762 {
00763 unsigned int variables_number = get_variables_number();
00764
00765
00766
00767 #ifdef _DEBUG
00768
00769 if(i >= variables_number)
00770 {
00771 std::ostringstream buffer;
00772
00773 buffer << "OpenNN Exception: VariablesInformation class.\n"
00774 << "void set_name(const unsigned int&, const std::string&) method.\n"
00775 << "Index of variable must be less than number of variables.\n";
00776
00777 throw std::logic_error(buffer.str());
00778 }
00779
00780 #endif
00781
00782 if(names.size() != variables_number)
00783 {
00784 names.set(variables_number);
00785
00786 }
00787
00788
00789
00790 names[i] = new_name;
00791 }
00792
00793
00794
00795
00799
00800 void VariablesInformation::set_units(const Vector<std::string>& new_units)
00801 {
00802
00803
00804 #ifdef _DEBUG
00805
00806 unsigned int variables_number = get_variables_number();
00807
00808 unsigned int size = new_units.size();
00809
00810 if(size != variables_number)
00811 {
00812 std::ostringstream buffer;
00813
00814 buffer << "OpenNN Exception: VariablesInformation class.\n"
00815 << "void set_units(const Vector<std::string>&) method.\n"
00816 << "Size must be equal to number of variables.\n";
00817
00818 throw std::logic_error(buffer.str());
00819 }
00820
00821 #endif
00822
00823 units = new_units;
00824 }
00825
00826
00827
00828
00833
00834 void VariablesInformation::set_units(const unsigned int& i, const std::string& new_units)
00835 {
00836 unsigned int variables_number = get_variables_number();
00837
00838
00839
00840 #ifdef _DEBUG
00841
00842 if(i >= variables_number)
00843 {
00844 std::ostringstream buffer;
00845
00846 buffer << "OpenNN Exception: VariablesInformation class.\n"
00847 << "void set_units(const unsigned int&, const std::string&) method.\n"
00848 << "Index of variable must be less than number of variables.\n";
00849
00850 throw std::logic_error(buffer.str());
00851 }
00852
00853 #endif
00854
00855 if(units.size() != variables_number)
00856 {
00857 units.set(variables_number);
00858 }
00859
00860
00861
00862 units[i] = new_units;
00863 }
00864
00865
00866
00867
00871
00872 void VariablesInformation::set_descriptions(const Vector<std::string>& new_descriptions)
00873 {
00874
00875
00876 #ifdef _DEBUG
00877
00878 unsigned int variables_number = get_variables_number();
00879
00880 unsigned int size = new_descriptions.size();
00881
00882 if(size != variables_number)
00883 {
00884 std::ostringstream buffer;
00885
00886 buffer << "OpenNN Exception: VariablesInformation class.\n"
00887 << "void set_descriptions(const Vector<std::string>&) method.\n"
00888 << "Size must be equal to number of variables.\n";
00889
00890 throw std::logic_error(buffer.str());
00891 }
00892
00893 #endif
00894
00895 descriptions = new_descriptions;
00896 }
00897
00898
00899
00900
00905
00906 void VariablesInformation::set_description(const unsigned int& i, const std::string& new_description)
00907 {
00908 unsigned int variables_number = get_variables_number();
00909
00910
00911
00912 #ifdef _DEBUG
00913
00914 if(i >= variables_number)
00915 {
00916 std::ostringstream buffer;
00917
00918 buffer << "OpenNN Exception: VariablesInformation class.\n"
00919 << "void set_description(const unsigned int&, const std::string&) method.\n"
00920 << "Index of variable must be less than number of variables.\n";
00921
00922 throw std::logic_error(buffer.str());
00923 }
00924
00925 #endif
00926
00927 if(descriptions.size() != variables_number)
00928 {
00929 descriptions.set(variables_number);
00930 }
00931
00932
00933
00934 descriptions[i] = new_description;
00935 }
00936
00937
00938
00939
00944
00945 void VariablesInformation::set_display(const bool& new_display)
00946 {
00947 display = new_display;
00948 }
00949
00950
00951
00952
00956
00957 void VariablesInformation::set_variables_number(const unsigned int& new_variables_number)
00958 {
00959 variables_number = new_variables_number;
00960
00961 if(new_variables_number == 0)
00962 {
00963 inputs_indices.set();
00964 targets_indices.set();
00965 }
00966 else if(new_variables_number == 1)
00967 {
00968 inputs_indices.set(1, 0);
00969 targets_indices.set(1, 0);
00970 }
00971 else
00972 {
00973 inputs_indices.set(new_variables_number-1);
00974 inputs_indices.initialize_sequential();
00975
00976 targets_indices.set(1, new_variables_number-1);
00977 }
00978
00979 names.set(new_variables_number);
00980 units.set(new_variables_number);
00981 descriptions.set(new_variables_number);
00982 }
00983
00984
00985
00986
00988
00989 std::string VariablesInformation::to_string(void) const
00990 {
00991 std::ostringstream buffer;
00992
00993 buffer << "Variables information\n"
00994 << "Variables number: " << variables_number << "\n"
00995 << "Input indices: " << inputs_indices << "\n"
00996 << "Target indices: " << targets_indices << "\n";
00997
00998 buffer << "Names\n";
00999
01000 for(unsigned int i = 0; i < variables_number; i++)
01001 {
01002 buffer << "Variable " << i+1 << ": " << names[i] << "\n";
01003 }
01004
01005 buffer << "Units\n";
01006
01007 for(unsigned int i = 0; i < variables_number; i++)
01008 {
01009 buffer << "Variable " << i+1 << ": " << units[i] << "\n";
01010 }
01011
01012 buffer << "Descriptions\n";
01013
01014 for(unsigned int i = 0; i < variables_number; i++)
01015 {
01016 buffer << "Variable " << i+1 << ": " << descriptions[i] << "\n";
01017 }
01018
01019 buffer << "Display: " << display << "\n";
01020
01021 return(buffer.str());
01022 }
01023
01024
01025
01026
01029
01030 TiXmlElement* VariablesInformation::to_XML(void) const
01031 {
01032 std::ostringstream buffer;
01033
01034
01035
01036 TiXmlElement* variables_information_element = new TiXmlElement("VariablesInformation");
01037 variables_information_element->SetAttribute("Version", 4);
01038
01039
01040
01041 TiXmlElement* variables_number_element = new TiXmlElement("VariablesNumber");
01042 variables_information_element->LinkEndChild(variables_number_element);
01043
01044 buffer.str("");
01045 buffer << variables_number;
01046
01047 TiXmlText* variables_number_text = new TiXmlText(buffer.str().c_str());
01048 variables_number_element->LinkEndChild(variables_number_text);
01049
01050
01051
01052 if(!names.empty())
01053 {
01054 TiXmlElement* names_element = new TiXmlElement("Names");
01055 variables_information_element->LinkEndChild(names_element);
01056
01057 for(unsigned int i = 0; i < variables_number; i++)
01058 {
01059 TiXmlElement* element = new TiXmlElement("Name");
01060 element->SetAttribute("Index", i+1);
01061 names_element->LinkEndChild(element);
01062
01063 TiXmlText* text = new TiXmlText(names[i].c_str());
01064 element->LinkEndChild(text);
01065 }
01066 }
01067
01068
01069
01070 if(!units.empty())
01071 {
01072 TiXmlElement* units_element = new TiXmlElement("Units");
01073 variables_information_element->LinkEndChild(units_element);
01074
01075 for(unsigned int i = 0; i < variables_number; i++)
01076 {
01077 TiXmlElement* element = new TiXmlElement("Unit");
01078 element->SetAttribute("Index", i+1);
01079 units_element->LinkEndChild(element);
01080
01081 TiXmlText* text = new TiXmlText(units[i].c_str());
01082 element->LinkEndChild(text);
01083 }
01084 }
01085
01086
01087
01088 if(!descriptions.empty())
01089 {
01090 TiXmlElement* descriptions_element = new TiXmlElement("Descriptions");
01091 variables_information_element->LinkEndChild(descriptions_element);
01092
01093 for(unsigned int i = 0; i < variables_number; i++)
01094 {
01095 TiXmlElement* element = new TiXmlElement("Description");
01096 element->SetAttribute("Index", i+1);
01097 descriptions_element->LinkEndChild(element);
01098
01099 TiXmlText* text = new TiXmlText(descriptions[i].c_str());
01100 element->LinkEndChild(text);
01101 }
01102 }
01103
01104
01105
01106 if(!inputs_indices.empty())
01107 {
01108 TiXmlElement* inputs_indices_element = new TiXmlElement("InputIndices");
01109 variables_information_element->LinkEndChild(inputs_indices_element);
01110
01111 Vector<unsigned int> new_inputs_indices = inputs_indices + 1;
01112
01113 buffer.str("");
01114 buffer << new_inputs_indices;
01115
01116 TiXmlText* inputs_indices_text = new TiXmlText(buffer.str().c_str());
01117 inputs_indices_element->LinkEndChild(inputs_indices_text);
01118 }
01119
01120
01121
01122 if(!targets_indices.empty())
01123 {
01124 TiXmlElement* targets_indices_element = new TiXmlElement("TargetIndices");
01125 variables_information_element->LinkEndChild(targets_indices_element);
01126
01127 Vector<unsigned int> new_targets_indices = targets_indices + 1;
01128
01129 buffer.str("");
01130 buffer << new_targets_indices;
01131
01132 TiXmlText* targets_indices_text = new TiXmlText(buffer.str().c_str());
01133 targets_indices_element->LinkEndChild(targets_indices_text);
01134 }
01135
01136 return(variables_information_element);
01137 }
01138
01139
01140
01141
01144
01145 void VariablesInformation::from_XML(TiXmlElement* variables_information_element)
01146 {
01147 if(!variables_information_element)
01148 {
01149 std::ostringstream buffer;
01150
01151 buffer << "OpenNN Exception: VariablesInformation class.\n"
01152 << "void from_XML(TiXmlElement*) method.\n"
01153 << "Pointer to variables information element is NULL.\n";
01154
01155 throw std::logic_error(buffer.str());
01156 }
01157
01158 int index = 0;
01159
01160
01161
01162 TiXmlElement* variables_number_element = variables_information_element->FirstChildElement("VariablesNumber");
01163
01164 if(variables_number_element)
01165 {
01166 unsigned int new_variables_number = atoi(variables_number_element->GetText());
01167
01168 try
01169 {
01170 set_variables_number(new_variables_number);
01171 }
01172 catch(std::exception& e)
01173 {
01174 std::cout << e.what() << std::endl;
01175 }
01176 }
01177
01178
01179
01180 TiXmlElement* inputs_indices_element = variables_information_element->FirstChildElement("InputIndices");
01181
01182 if(inputs_indices_element)
01183 {
01184 Vector<unsigned int> new_inputs_indices;
01185 new_inputs_indices.parse(inputs_indices_element->GetText());
01186 new_inputs_indices -= 1;
01187
01188 try
01189 {
01190 set_inputs_indices(new_inputs_indices);
01191 }
01192 catch(std::exception& e)
01193 {
01194 std::cout << e.what() << std::endl;
01195 }
01196 }
01197
01198
01199
01200 TiXmlElement* targets_indices_element = variables_information_element->FirstChildElement("TargetIndices");
01201
01202 if(targets_indices_element)
01203 {
01204 Vector<unsigned int> new_targets_indices;
01205 new_targets_indices.parse(targets_indices_element->GetText());
01206 new_targets_indices -= 1;
01207
01208 try
01209 {
01210 set_targets_indices(new_targets_indices);
01211 }
01212 catch(std::exception& e)
01213 {
01214 std::cout << e.what() << std::endl;
01215 }
01216 }
01217
01218
01219
01220 TiXmlElement* names_element = variables_information_element->FirstChildElement("Names");
01221
01222 if(names_element)
01223 {
01224 Vector<std::string> new_names(variables_number);
01225
01226 TiXmlElement* name_element = names_element->FirstChildElement("Name");
01227
01228 if(name_element)
01229 {
01230 name_element->QueryIntAttribute("Index", &index);
01231
01232 if(name_element->GetText())
01233 {
01234 new_names[index-1] = name_element->GetText();
01235 }
01236
01237 for( ; name_element; name_element=name_element->NextSiblingElement())
01238 {
01239 name_element->QueryIntAttribute("Index", &index);
01240
01241 if(name_element->GetText())
01242 {
01243 new_names[index-1] = name_element->GetText();
01244 }
01245 }
01246 }
01247
01248 try
01249 {
01250 set_names(new_names);
01251 }
01252 catch(std::exception& e)
01253 {
01254 std::cout << e.what() << std::endl;
01255 }
01256 }
01257
01258
01259
01260 TiXmlElement* units_element = variables_information_element->FirstChildElement("Units");
01261
01262 if(units_element)
01263 {
01264 Vector<std::string> new_units(variables_number);
01265
01266 TiXmlElement* variable_units_element = units_element->FirstChildElement("Unit");
01267
01268 if(variable_units_element)
01269 {
01270 variable_units_element->QueryIntAttribute("Index", &index);
01271
01272 if(variable_units_element->GetText())
01273 {
01274 new_units[index-1] = variable_units_element->GetText();
01275 }
01276
01277 for( ; variable_units_element; variable_units_element=variable_units_element->NextSiblingElement())
01278 {
01279 variable_units_element->QueryIntAttribute("Index", &index);
01280
01281 if(variable_units_element->GetText())
01282 {
01283 new_units[index-1] = variable_units_element->GetText();
01284 }
01285 }
01286 }
01287
01288 try
01289 {
01290 set_units(new_units);
01291 }
01292 catch(std::exception& e)
01293 {
01294 std::cout << e.what() << std::endl;
01295 }
01296 }
01297
01298
01299
01300 TiXmlElement* descriptions_element = variables_information_element->FirstChildElement("Descriptions");
01301
01302 if(descriptions_element)
01303 {
01304 Vector<std::string> new_descriptions(variables_number);
01305
01306 TiXmlElement* variable_description_element = descriptions_element->FirstChildElement("Description");
01307
01308 if(variable_description_element)
01309 {
01310 variable_description_element->QueryIntAttribute("Index", &index);
01311
01312 if(variable_description_element->GetText())
01313 {
01314 new_descriptions[index-1] = variable_description_element->GetText();
01315 }
01316
01317 for( ; variable_description_element; variable_description_element=variable_description_element->NextSiblingElement())
01318 {
01319 variable_description_element->QueryIntAttribute("Index", &index);
01320
01321 if(variable_description_element->GetText())
01322 {
01323 new_descriptions[index-1] = variable_description_element->GetText();
01324 }
01325 }
01326 }
01327
01328 try
01329 {
01330 set_descriptions(new_descriptions);
01331 }
01332 catch(std::exception& e)
01333 {
01334 std::cout << e.what() << std::endl;
01335 }
01336 }
01337 }
01338
01339 }
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357