Evaluating cognitive complexity measure with weyuker ... - IEEE Xplore

2 downloads 0 Views 249KB Size Report
Motilal Nehru National Institute of Technology, Allahabad, India. *Permanent address: United College of Engineering and Research, Naini, Allahabad , India.
Evaluating Cognitive Complexity Measure with Weyuker Properties Sanjay Misra* and A.K.Misra Department of Comuter Science and Engineering Motilal Nehru National Institute of Technology, Allahabad, India *Permanent address: United College of Engineering and Research, Naini, Allahabad , India Email: [email protected], arun [email protected]

Abstract

by evaluating this against the nine Weyuker properties[13].

Cognitive complexity measure is based on Cognitive informatics, which in turn helps in comprehending the software characteristics. Weyuker properties must be satisfied by every complexity measure to qualify as a good and comprehensive one. In this paper, an attempt has been made to evaluate cognitive complexity measure in terms of nine Weyuker properties, through examples. It has been found that eight of nine Weyuker properties have been satisfied by the cognitive weight software complexity measure and hence establishes the cognitive complexity as a well structured one.

2. Cognitive Weights of a Software And Software Complexity Based on It

Keywords: Cognitive weight, Basic control Structures, Software complexity, Software functional size.

1. Introduction Many well-known software complexity measures have been proposed such as Mc Cabe’s cyclomatic number[6], Halstead programming effort[3], Oviedo’s data flow complexity measures[7], Basili’s measure[1][2] and others[5]. All the reported complexity measures are supposed to cover the correctness, effectiveness and clarity of software and also to provide a good estimate of these parameters. Out of the numerous proposed measures, which software complexity measure should be chosen is again a problem, as every measure has its own advantages and disadvantages. There is a continuous effort to find such a comprehensive complexity measure, which addresses most of the parameters of software. Further, scope of introducing a complexity measure is always there, because the principal (prime) objective of a complexity measure is to evaluate the quality of software in terms of number. Weyuker [13] has suggested nine properties, which are used to determine the effectiveness of various software complexity measures. A good complexity measure should satisfy most of the Weyuker properties. A new complexity measure based on the cognitive weights of the software has been developed and reported in [9], which is capable of evaluating complexity from both architectural and cognitive aspects. In this paper an effort has been made to estimate this measure as a good and comprehensive one

Basic control structures [BCS] such as sequence, branch and iteration [11][8] are the basic logic building blocks of any software and the cognitive weight of software [9] is the extent of difficulty or relative time and effort for comprehending a given software modeled by a number of BCS’s. These cognitive weights for BCS’s measure the complexity of logical structure of the software. There are two different architectures[4][10] for calculating Wbcs[9]. Either all the BCS’s are in a linear layout or some BCS’s are embedded in others. For the former case, we sum the weights of all n BCS’s and for the latter, cognitive weights of inner BCS’s are multiplied with the weights of external BCS’s. The total cognitive weight of a software component Wc is defined as the sum of cognitive weight of its q linear blocks composed in individuals BCS’s. Since each block may consists of m layers of nested BCS’s, and each layer with n linear BCS’s, the total cognitive weight, Wc can be calculated by: q  n m   Wc = { [ Wc (j, k, i)]} [CW U ] (1) j=1 k=1 i=1

If there is no embedded BCS in any of the m components, i.e., m=1,then Equation 1 can be simplified as: Wc =

q  n 

Wc (j, k, i)

(2)

j=1 i=1

The component’s cognitive functional size is proportional to the total weighted cognitive complexity of all internal BCS’s and the number of inputs (Ni ) and outputs (No )[12]. The unit of cognitive weight (CWU) of software, Sf o , is defined as the cognitive weight of the simplest software component with only single I/O and a linear structure BCS, i.e. Sf o = (Ni + No )Wi

(3)

= f (Ni/o , Wbcs ) The cognitive functional size of a basic software component

Proceedings of the Third IEEE International Conference on Cognitive Informatics (ICCI’04) 0-7695-2190-8/04 $20.00 © 2004 IEEE

that only consists of one method, Sf is defined as a product of the sum of inputs and outputs (Ni/o ) and the total cognitive weight, i.e. q  m  n  Sf o = (Ni + No ){ [ Wc (j, k, i)[CW U ]) (4) j=1 k=1 i=1

= Ni/o ∗ Wc Based on 4, the CFS of a complex component, Sf (c), can be derived as follows: Sf (c) =

n 

Sf (c)[CW U ]

(5)

c=1

Where Sf (c) is the CFS of the cth method that can be directly measured according to equation 4.

3. Evaluation of Cognitive Complexity Measure Weyuker[13] proposed the nine properties to evaluate compare and construct any software complexity measure. These properties also evaluate the weaknesses of a measure in a concrete way and in turn lead to the definition of really good notions of software complexity. With the help of these properties one can determine the most suitable measure among the different available complexity measures. In the following paragraphs the cognitive complexity measure[9] has been evaluated against the Weyuker properties for establishing itself as a good and comprehensive measure and also to determine its strength and weaknesses. Property 1: (∃P )(∃Q)(|P | = |Q|). Where P and Q are programme body. This property states that a measure should not rank all pro#include< stdio.h > #include< math.h > #include< conio.h > /*Calculate the sum of first n integer*/ main() { int i, n; int sum=0; printf(”Enter the number”); //BCS1 scanf(”%d”, &n); for (i=1;i #include< stdlib.h > /* Calculate the sum of all the numbers between a & b */ #define min range 0 #define max range 30000 int main() { long a,b,sum=0; printf(”\n input the first number a”); //BCS1 scanf(”%i”,&a); printf(”\n input the second number b”); scanf(”%i”,&b); if ((min range #include< math.h > /* Calculate the real roots of given quadratic equation */ main(){ int a,b,c; long def; float x1,x2; printf(”\ n input the numbers a & b”); //BCS1 scanf(”%d%d”,&a,&b); printf(”\n enter the constant”); scanf(”%d”,&c); def=b*b-4*a*c; if(def>0) //BCS2 {x1=-b+sqrt(def)/2*a; x2=-b-sqrt(def)/2*a; printf (”%d”, sqrt (x1*x1+x2*x2));} else printf (”the roots are imaginary”); return()} Fig 3. Source code of calculation of the real roots of quadratic equations

cognitive weight of these two BCS’s can be determined as follows: BCS1 (sequence) W1 = 1 BCS2 (branch)W2 = 2 According to equation 3,the CFS of this algorithm can be derived as Sf o = (Ni + No ) ∗ Wc = (2 + 1) ∗ 3 = 9 [CWU] Considering two programs given in fig 2 and 3 it is clear that for two distinct programs the cognitive functional size is same i.e. 9. So this property is satisfied by the cognitive weight software complexity measure. Property 4: (∃P )(∃Q)(P ≡ Q & |P | =  |Q|). Considering again the program given in Fig. 1 in which for loop is replaced by the formula s= (b+1)b/2 , which will not affect the output. For this changed program, Ni = 1, No = 1. There are only one sequential BCS. The cognitive weight of the BCS’s can be determined as follows: BCS1 (sequence) W1 =1 According to equation 3, the CFS of this algorithm can be derived as Sf o = (Ni + No ) ∗ Wc = (1+1)*1=2 [CWU] For measuring the sum of first n integer by two different algorithm, it is observed that the cognitive functional sizes for the two algorithms of same object are different. Therefore, this property is also satisfied by the given measure Property 5: (∀P )(∀Q)(|P | ≤ |P ; Q| and |Q| ≤ |P ; Q|). Cognitive functional size is an integer and the set of integers with operator holds the following property (∃P )(∃Q)(P ≤ P + Q) and (Q ≤ P + Q) Since this equation and Weyuker’s property 5 are analogous and as such property 5 is satisfied by cognitive complexity measure.

An alternative proof of this property also exists by taking an example of the two-program bodies. For program given in Fig. 4 there is one main program with two-program body. The BCS of the main program and two-program body are given separately. The program body for finding out the factorial of the num#include< stdio.h > #include< stdlib.h > #include< conio.h > int main() { long fact(int n); int isprime(int n); int n; long int temp; clrscr(); printf(”\n input the number”); scanf(”%d”,&n); temp=fact(n); {printf(”\n is prime”);} int flag1=isprime(n); if (flag1==1) else {printf(”\n is not prime”)}; printf(”\ n factorial(n)=%d”,temp); getch(); long fact(int n) { long int facto=1; if (n==0) facto=1; else facto=n*fact(n-1); return(facto); } int isprime(int n) { int flag; if (n==2) flag=1; else for (int i=2;i #include< stdlib.h > #include< conio.h > int main() { int flag = 1,n; clrscr(); printf(”\ n enter the number”); scanf(”%d”,&n); if (n==2) flag=1; else {for (int i=2;i #include< stdlib.h > #include< conio.h > int main () { long int fact=1; int n; clrscr(); printf(”\ input the number”); scanf(”%d”,&n); if (n==0) else for(int i=n;i>1;i–) fact=fact*i; printf(”\n factorial (n)=%ld”,fact); getch();}

//BCS1 //BCS2 //BCS3

Fig 6. Source code for calculation of factorial of a number //BCS5

Fig 5. Source code for checking prime number

mined as follows: BCS31 (sequence) W31 = 1 BCS32 (branch) W32 =2 BCS33 (iteration) W33 =3 BCS34 (branch) W34 =2 The CFS of this algorithm can be derived as Sf o = (Ni + No ) ∗ Wc =1*(1+3*2*3)=13 [CWU] For the main program body for finding out the prime and factorial of the number, there are one sequential, two call, one branch BCS’s. The cognitive weight of the BCS’s can be determined as follows: BCS11 (sequence) W11 =1 BCS12 (call & fact) W12 = 5 (for call=2 and fact=3) BCS13 (call) W13 =15 (for call=2 & prime=13) BCS14 (branch) W14 = 2 the CFS of this algorithm can be derived as Sf o = (Ni + No ) ∗ Wc =2*(1+15+5+2)=46 [CWU] For program given in Fig. 5, Ni = 1, No = 1. There is one sequential, one iteration and two branch BCS’s. The cognitive weight of the BCS’s can be determined as follows: BCS1 (sequence) W1 =1 BCS2 (branch)W2 =2 BCS3 (iteration)W3 = 3 BCS4 (branch) W4 =2 BCS5 (branch) W5 =2 The CFS of this algorithm can be derived as Sf o = (Ni + No ) ∗ Wc =(1+1)*(1+2*3*2+2)=30 [CWU] For program given in Fig. 6, Ni = 1, No = 1. There is one sequential, one iteration and one branch BCS’s. The cognitive weight of the BCS’s can be determined as follows:

BCS1 (sequence) W1 =1 BCS2 (branch) W2 =2 BCS3 (iteration) W3 =3 The CFS of this algorithm can be derived as Sf o = (Ni + No ) ∗ Wc =(1+1)*(1+3*2)=14 [CWU] It is clear from the above example that if we take the two program body, one for calculating the factorial and another for checking for prime whose cognitive weight complexity are 14 and 30 which is less than P+Q i.e. 46. So property five also holds for this complexity measure. Property 6a: (∃P )(∃Q)(∃R)(|P | = |Q|) & (|P ; R| = |Q; R|). 6b: (∃P )(∃Q)(∃R)(|P | = |Q|) & (|R; P | =  |R; Q|). Since in cognitive function size measure the cognitive weight of BCS’s are fixed. That is cognitive weight of a particular BCS will be same in all programs therefore joining program R with P and Q adds the same amount of complexity hence property 6 is not satisfied by this measure. Property 7: There are program bodies P and Q such that Q is formed by permuting the order of the statements of P, and (|P| = |Q|). Since cognitive weights of BCS’s depend on the sequence of the statement, so if program body Q is formed by permuting the order of statements of P then it is possible that (|P | = |Q|). It can be proved from the programmes given in Fig. 7 and 8 where Q is the result of permuting the order of statement of P. For program given in Fig. 7, Ni = 2, No = 1. There is one sequential, one iteration and one branch BCS’s. The cognitive weight of the BCS’s can be determined as follows: BCS1 (sequence) W1 =1 BCS2 (iteration) W2 = 3 BCS3 (branch)W3 = 2 The CFS of this algorithm can be derived as Sf o = (Ni + No ) ∗ Wc =(2+1)*(1+3*2)=21 [CWU] For program given in Fig. 8, Ni =2, No =1. There is one sequential, one iteration and one branch

Proceedings of the Third IEEE International Conference on Cognitive Informatics (ICCI’04) 0-7695-2190-8/04 $20.00 © 2004 IEEE

#include < stdio.h > #include< stdlib.h > #include< conio.h > main () { int i,j; clrscr(); for(i=0;i #include< stdlib.h > main() { int i,j; for (i=0;i