COIN-OR::LEMON - Graph Library

Changeset 118:cfd49e5c8723 in glemon-0.x for new_map_win.cc


Ignore:
Timestamp:
01/10/06 16:15:57 (18 years ago)
Author:
Hegyi Péter
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2463
Message:

If default value of a new map is constant, the newly created elements will get that value as well. Documentation is added to BrokenEdge?, MapStorage? and GraphDisplazCanvas? classes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new_map_win.cc

    r117 r118  
    7373      //get and formulate text
    7474      std::string def_val_str=default_value.get_text();
    75       std::string polishform=string2Polishform(def_val_str,edge.get_active());
     75
     76      bool only_nums=true;
     77      for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
     78        {
     79          if( def_val_str[i]<'0' || def_val_str[i]>'9' )
     80            {
     81              only_nums=false;
     82            }
     83        }
     84      std::string polishform;
     85
     86      if(only_nums)
     87        {
     88          def_val=atof(def_val_str.c_str());
     89        }
     90      else
     91        {
     92          polishform=string2Polishform(def_val_str,edge.get_active());
     93        }
    7694
    7795      //get name of text
    7896      std::string mapname=name.get_text();
    79 
    80       if(!mapname.empty()&&!polishform.empty())
     97     
     98      if(!mapname.empty()&&(!polishform.empty()||only_nums))
    8199        {
    82100          int abortion=0;
     
    84102            {
    85103              //create the new map
    86               Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph);
    87 
    88               std::stack<double> polishstack;
    89  
    90               for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    91                 {
    92                   for(int i=0;i<(int)polishform.size();i++)
     104              Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph, def_val);
     105             
     106              if(!only_nums)
     107                {
     108                  std::stack<double> polishstack;
     109                 
     110                  for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    93111                    {
    94                       double op1, op2;
    95                       bool operation=true;
    96                       switch(polishform[i])
     112                      for(int i=0;i<(int)polishform.size();i++)
    97113                        {
    98                         case '+':
    99                         case '-':
    100                         case '/':
    101                         case '*':
    102                           op1=polishstack.top();
    103                           polishstack.pop();
    104                           op2=polishstack.top();
    105                           polishstack.pop();
    106                           break;
    107                         default:
    108                           //substitute variable
    109                           std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
    110                           bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
    111                           if(itisvar)
    112                             {
    113                               polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    114                             }
    115                           else
    116                             {
    117                               polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
    118                             }
    119                           operation=false;
    120                           break;
    121                         }
    122                       if(operation)
    123                         {
    124                           double res;
     114                          double op1=0, op2=0;
     115                          bool operation=true;
    125116                          switch(polishform[i])
    126117                            {
    127118                            case '+':
    128                               res=op1+op2;
    129                               break;
    130119                            case '-':
    131                               res=op2-op1;
    132                               break;
    133120                            case '/':
    134                               res=op2/op1;
    135                               break;
    136121                            case '*':
    137                               res=op1*op2;
     122                              op1=polishstack.top();
     123                              polishstack.pop();
     124                              op2=polishstack.top();
     125                              polishstack.pop();
    138126                              break;
    139127                            default:
    140                               std::cout << "How could we get here?" << std::endl;
     128                              //substitute variable
     129                              std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
     130                              bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
     131                              if(itisvar)
     132                                {
     133                                  polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
     134                                }
     135                              else
     136                                {
     137                                  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
     138                                }
     139                              operation=false;
    141140                              break;
    142141                            }
    143                           polishstack.push(res);
    144                         }
    145                     }
    146                   (*emptr)[k]=polishstack.top();
    147                 }
     142                          if(operation)
     143                            {
     144                              double res;
     145                              switch(polishform[i])
     146                                {
     147                                case '+':
     148                                  res=op1+op2;
     149                                  break;
     150                                case '-':
     151                                  res=op2-op1;
     152                                  break;
     153                                case '/':
     154                                  res=op2/op1;
     155                                  break;
     156                                case '*':
     157                                  res=op1*op2;
     158                                  break;
     159                                default:
     160                                  std::cout << "How could we get here?" << std::endl;
     161                                  break;
     162                                }
     163                              polishstack.push(res);
     164                            }
     165                        }//foreach letter in polishform
     166                      (*emptr)[k]=polishstack.top();
     167                    }//foreach edge
     168                }//!only_nums
    148169
    149170              //if addition was not successful addEdgeMap returns one.
     
    164185            {
    165186              //create the new map
    166               Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph);
    167 
    168               std::stack<double> polishstack;
     187              Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph, def_val);
     188
     189              if(!only_nums)
     190                {
     191                  std::stack<double> polishstack;
    169192 
    170               for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    171                 {
    172                   for(int i=0;i<(int)polishform.size();i++)
     193                  for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    173194                    {
    174                       double op1, op2;
    175                       bool operation=true;
    176                       switch(polishform[i])
     195                      for(int i=0;i<(int)polishform.size();i++)
    177196                        {
    178                         case '+':
    179                         case '-':
    180                         case '/':
    181                         case '*':
    182                           op1=polishstack.top();
    183                           polishstack.pop();
    184                           op2=polishstack.top();
    185                           polishstack.pop();
    186                           break;
    187                         default:
    188                           std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
    189                           bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
    190                           if(itisvar)
    191                             {
    192                               polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    193                             }
    194                           else
    195                             {
    196                               polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
    197                             }
    198                           operation=false;
    199                           break;
    200                         }
    201                       if(operation)
    202                         {
    203                           double res;
     197                          double op1=0, op2=0;
     198                          bool operation=true;
    204199                          switch(polishform[i])
    205200                            {
    206201                            case '+':
    207                               res=op1+op2;
    208                               break;
    209202                            case '-':
    210                               res=op2-op1;
    211                               break;
    212203                            case '/':
    213                               res=op2/op1;
    214                               break;
    215204                            case '*':
    216                               res=op1*op2;
     205                              op1=polishstack.top();
     206                              polishstack.pop();
     207                              op2=polishstack.top();
     208                              polishstack.pop();
    217209                              break;
    218210                            default:
    219                               std::cout << "How could we get here?" << std::endl;
     211                              std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
     212                              bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
     213                              if(itisvar)
     214                                {
     215                                  polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
     216                                }
     217                              else
     218                                {
     219                                  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
     220                                }
     221                              operation=false;
    220222                              break;
    221223                            }
    222                           polishstack.push(res);
     224                          if(operation)
     225                            {
     226                              double res;
     227                              switch(polishform[i])
     228                                {
     229                                case '+':
     230                                  res=op1+op2;
     231                                  break;
     232                                case '-':
     233                                  res=op2-op1;
     234                                  break;
     235                                case '/':
     236                                  res=op2/op1;
     237                                  break;
     238                                case '*':
     239                                  res=op1*op2;
     240                                  break;
     241                                default:
     242                                  std::cout << "How could we get here?" << std::endl;
     243                                  break;
     244                                }
     245                              polishstack.push(res);
     246                            }
    223247                        }
     248                      (*emptr)[k]=polishstack.top();
    224249                    }
    225                   (*emptr)[k]=polishstack.top();
    226                 }
    227 
     250                }
    228251              //if addition was not successful addNodeMap returns one.
    229252              //cause can be that there is already a map named like the new one
Note: See TracChangeset for help on using the changeset viewer.