www.gusucode.com > matlab的GA工具箱与vc混和实现遗传算法源码程序 > parse.cpp

      #include "matlib.h"
  #pragma hdrstop
  
  #include "parse.h"
  
  
  Mm parse(Mm inStr) {
    begin_scope
    inStr.setname("inStr"); 
    dMm(x); dMm(sz); dMm(strLen); dMm(wordCount); dMm(last); dMm(i_); dMm(i_parse_v0); 
    
    call_stack_begin;
    // nargin, nargout entry code
    double old_nargin=nargin_val; if (!nargin_set) nargin_val=1.0;
    nargin_set=0;
    double old_nargout=nargout_val; if (!nargout_set) nargout_val=1.0;
    nargout_set=0;
    
    // translated code
    
    // parse is a function which takes in a string vector of blank separated text
    // and parses out the individual string items into a n item matrix, one row
    // for each string.
    //
    // function [x] = parse(inStr)
    // x     - the return matrix of strings
    // inStr - the blank separated string vector
    
    // Binary and Real-Valued Simulation Evolution for Matlab 
    // Copyright (C) 1996 C.R. Houck, J.A. Joines, M.G. Kay 
    //
    // C.R. Houck, J.Joines, and M.Kay. A genetic algorithm for function
    // optimization: A Matlab implementation. ACM Transactions on Mathmatical
    // Software, Submitted 1996.
    //
    // This program is free software; you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation; either version 1, or (at your option)
    // any later version.
    //
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details. A copy of the GNU 
    // General Public License can be obtained from the 
    // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
    sz = size(inStr);
    strLen = sz(2.0);
    x = blanks(strLen);
    wordCount = 1.0;
    last = 0.0;
    i_parse_v0 = colon(1.0,1.0,strLen); int i_parse_i0;
    for (i_parse_i0=0;i_parse_i0<i_parse_v0.cols();i_parse_i0++) {
      forelem(i_,i_parse_v0,i_parse_i0);
      if (istrue(inStr(i_)==TM(" "))) {
        wordCount = wordCount+1.0;
        x(wordCount,c_p) = blanks(strLen);
        last = i_;
      } else {
        
        x(wordCount,i_-last) = inStr(i_);
      }
    }
    
    call_stack_end;
    
    // nargin, nargout exit code
    nargin_val=old_nargin; nargout_val=old_nargout;
    
    // function exit code
    inStr.setname(NULL); 
    return x;
    end_scope
  }