Ignore:
Timestamp:
05/29/18 16:24:39 (6 years ago)
Author:
Maciej Komosinski
Message:

Code formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/neuro/impl/neuroimpl-fuzzy-f0.cpp

    r348 r791  
    1414int FuzzyF0String::convertStrToSets(const SString& str, double numbers[], int nrOfSets)
    1515{
    16   int pos=0;
    17   SString t;
    18   int have=0;
    19   int maxnumbers=4*nrOfSets; //number of semicolons should be equal 4*nrOfSets
     16        int pos = 0;
     17        SString t;
     18        int have = 0;
     19        int maxnumbers = 4 * nrOfSets; //number of semicolons should be equal 4*nrOfSets
    2020
    21   while (str.getNextToken(pos,t,';'))
    22     if (have>=maxnumbers)
    23       break;
    24     else
    25       numbers[have++]=atof(t.c_str());
     21        while (str.getNextToken(pos, t, ';'))
     22                if (have >= maxnumbers)
     23                        break;
     24                else
     25                        numbers[have++] = atof(t.c_str());
    2626
    27   //check if number of read numbers (separated with semicolon) is equal to declared
    28   if (have != 4*nrOfSets)
    29     return -1; //number of sets found is lower than declared!
     27        //check if number of read numbers (separated with semicolon) is equal to declared
     28        if (have != 4 * nrOfSets)
     29                return -1; //number of sets found is lower than declared!
    3030
    31   //check corectness of sets - must not be decreasing
    32   for(int i=0;i<nrOfSets;i++)
    33     if((numbers[4*i]>numbers[4*i+1])||(numbers[4*i+1]>numbers[4*i+2])||(numbers[4*i+2]>numbers[4*i+3]))
    34       return -2; //error
     31        //check corectness of sets - must not be decreasing
     32        for (int i = 0; i < nrOfSets; i++)
     33                if ((numbers[4 * i] > numbers[4 * i + 1]) || (numbers[4 * i + 1] > numbers[4 * i + 2]) || (numbers[4 * i + 2] > numbers[4 * i + 3]))
     34                        return -2; //error
    3535
    36   return 0;
     36        return 0;
    3737}
    3838
     
    4747int FuzzyF0String::countInputsOutputs(const char* str, int ruldef[], int rulesNr)
    4848{ //ruledef will remember counted number of inputs and outputs for every rule
    49   const char* t;
    50   int separators=0, inouts=0;
     49        const char* t;
     50        int separators = 0, inouts = 0;
    5151
    52   for(t=str;*t;t++)
    53   {
    54     while(isdigit(*t))
    55       t++; //only count, does not care about numbers now
    56     if (!*t)
    57       break; //end of the string - get out of 'for' loop
    58     if ( (*t==';')||(*t==':')||(*t=='/') ) //found sth different than digit - it must be a separator
    59     {
    60       separators++; //one of separators
    61       if (*t!=';') // end of [conditional part of] rule
    62       {
    63         if (inouts >= 2*rulesNr) //more rules declared in string than declared in rulesNr
    64           return -2;
    65         ruldef[inouts]=(separators+1)/2; //cause fuzzy sets - for 1 in/out there are 2 semicolons
    66         separators=0;  //begin counting number of in/out from zero
    67         inouts++; //next part of rule / or next rule
    68       }
    69     }
    70     else // illegal character
    71       return -1;
    72   }
     52        for (t = str; *t; t++)
     53        {
     54                while (isdigit(*t))
     55                        t++; //only count, does not care about numbers now
     56                if (!*t)
     57                        break; //end of the string - get out of 'for' loop
     58                if ((*t == ';') || (*t == ':') || (*t == '/')) //found sth different than digit - it must be a separator
     59                {
     60                        separators++; //one of separators
     61                        if (*t != ';') // end of [conditional part of] rule
     62                        {
     63                                if (inouts >= 2 * rulesNr) //more rules declared in string than declared in rulesNr
     64                                        return -2;
     65                                ruldef[inouts] = (separators + 1) / 2; //cause fuzzy sets - for 1 in/out there are 2 semicolons
     66                                separators = 0;  //begin counting number of in/out from zero
     67                                inouts++; //next part of rule / or next rule
     68                        }
     69                }
     70                else // illegal character
     71                        return -1;
     72        }
    7373
    74   //check, if nr of found rules is equal to declared
    75   if (inouts == 2*rulesNr) //each rule has a conditional part (inputs) and decisional part (outputs)
    76     return 0;
    77   else
    78     return -5; // ShowMessage("Inconsistent number of rules!");
     74        //check, if nr of found rules is equal to declared
     75        if (inouts == 2 * rulesNr) //each rule has a conditional part (inputs) and decisional part (outputs)
     76                return 0;
     77        else
     78                return -5; // ShowMessage("Inconsistent number of rules!");
    7979}
    8080
     
    8383int FuzzyF0String::convertStrToRules(const SString& str, const int ruledef[], int **rules, int setsNr, int rulesNr, int &maxOutputNr)
    8484{
    85   int pos=0, j, k, len=str.len();
    86   int dNr=0, sNr=0;
    87   int inNr, outNr; //number of inputs/outputs and corresponding fuzzy sets
    88   SString t;
    89   bool conditional=true; //which part of rule: conditional or decisional
     85        int pos = 0, j, k, len = str.len();
     86        int dNr = 0, sNr = 0;
     87        int inNr, outNr; //number of inputs/outputs and corresponding fuzzy sets
     88        SString t;
     89        bool conditional = true; //which part of rule: conditional or decisional
    9090
    91   maxOutputNr=0; //sets maximum output nr found in rules string
     91        maxOutputNr = 0; //sets maximum output nr found in rules string
    9292
    93   //check corectness of the string: number semicolon ... separated with colon or slash
    94   while(pos<len)
    95   {
    96     while((pos<len)&&(isdigit(str.charAt(pos)))) pos++;
    97     if(!(pos<len))
    98       break; //end of the string
    99     if(str.charAt(pos)!=';')
    100       if((str.charAt(pos)==':')&&(conditional))
    101         {sNr++; conditional=false;}
    102       else if((str.charAt(pos)=='/')&&(!conditional))
    103         {dNr++; conditional=true;}
    104       else
    105         return -4; //error - illegal character
    106     pos++;
    107   }
    108   if( (dNr!=sNr) || (dNr!=rulesNr) )
    109     return -5; //error - wrong number of rules
     93        //check corectness of the string: number semicolon ... separated with colon or slash
     94        while (pos < len)
     95        {
     96                while ((pos < len) && (isdigit(str.charAt(pos)))) pos++;
     97                if (!(pos < len))
     98                        break; //end of the string
     99                if (str.charAt(pos) != ';')
     100                        if ((str.charAt(pos) == ':') && (conditional))
     101                        {
     102                        sNr++; conditional = false;
     103                        }
     104                        else if ((str.charAt(pos) == '/') && (!conditional))
     105                        {
     106                                dNr++; conditional = true;
     107                        }
     108                        else
     109                                return -4; //error - illegal character
     110                        pos++;
     111        }
     112        if ((dNr != sNr) || (dNr != rulesNr))
     113                return -5; //error - wrong number of rules
    110114
    111   pos=0;
     115        pos = 0;
    112116
    113   for(j=0;j<rulesNr;j++)
    114   { //sum of inputs and outputs
    115     inNr = 2*ruledef[2*j];
    116     outNr = 2*ruledef[2*j+1];
    117     for(k=0;k<inNr+outNr;k++)
    118     {
    119       t = ""; //clear previous value
    120       //cuts next integer values
    121       while ( (pos<len)&&(isdigit(str.charAt(pos))) )
    122         t += str.charAt(pos++);
    123       pos++;
    124       rules[j][k]=atol(t.c_str()); //convert cut out string into number
    125       //fuzzy sets - odd index table - are counted from 0,
    126       //so if 5 fuzzy sets declared, values acceptable are 0,1,2,3,4
    127       if ( ((k%2)!=0) && (rules[j][k] >= setsNr) )
    128         return -1;
    129       if((k>=inNr)&&((k%2)==0))
    130         maxOutputNr=max(maxOutputNr,rules[j][k]);
    131     }
    132   }
    133   return 0;
     117        for (j = 0; j < rulesNr; j++)
     118        { //sum of inputs and outputs
     119                inNr = 2 * ruledef[2 * j];
     120                outNr = 2 * ruledef[2 * j + 1];
     121                for (k = 0; k < inNr + outNr; k++)
     122                {
     123                        t = ""; //clear previous value
     124                        //cuts next integer values
     125                        while ((pos < len) && (isdigit(str.charAt(pos))))
     126                                t += str.charAt(pos++);
     127                        pos++;
     128                        rules[j][k] = atol(t.c_str()); //convert cut out string into number
     129                        //fuzzy sets - odd index table - are counted from 0,
     130                        //so if 5 fuzzy sets declared, values acceptable are 0,1,2,3,4
     131                        if (((k % 2) != 0) && (rules[j][k] >= setsNr))
     132                                return -1;
     133                        if ((k >= inNr) && ((k % 2) == 0))
     134                                maxOutputNr = max(maxOutputNr, rules[j][k]);
     135                }
     136        }
     137        return 0;
    134138}
    135 
Note: See TracChangeset for help on using the changeset viewer.