Evaluation of Complexity of Some Programming Languages on the Travelling Salesman Problem



Similar documents
Elevator Simulation and Scheduling: Automated Guided Vehicles in a Hospital

Branch-and-Price Approach to the Vehicle Routing Problem with Time Windows

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

High-Mix Low-Volume Flow Shop Manufacturing System Scheduling

STRATEGIC CAPACITY PLANNING USING STOCK CONTROL MODEL

Glossary of Object Oriented Terms

Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.

JUST-IN-TIME SCHEDULING WITH PERIODIC TIME SLOTS. Received December May 12, 2003; revised February 5, 2004

Pseudo code Tutorial and Exercises Teacher s Version

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Moving from CS 61A Scheme to CS 61B Java

P vs NP problem in the field anthropology

Project Planning and Project Estimation Techniques. Naveen Aggarwal

Java CPD (I) Frans Coenen Department of Computer Science

Automated SEO. A Market Brew White Paper

An Internet Course in Software Development with C++ for Engineering Students

The Classes P and NP. mohamed@elwakil.net

ARTIFICIAL INTELLIGENCE METHODS IN EARLY MANUFACTURING TIME ESTIMATION

Lecture 7: NP-Complete Problems

Research Paper Business Analytics. Applications for the Vehicle Routing Problem. Jelmer Blok

Structure Preserving Model Reduction for Logistic Networks

Computational complexity theory

Reductions & NP-completeness as part of Foundations of Computer Science undergraduate course

BCS Higher Education Qualifications. Professional Graduate Diploma in IT. Programming Paradigms Syllabus

What is a life cycle model?

INTEGRATED OPTIMIZATION OF SAFETY STOCK

Revenue Management for Transportation Problems

CS/COE

McGraw-Hill The McGraw-Hill Companies, Inc.,

vii TABLE OF CONTENTS CHAPTER TITLE PAGE DECLARATION DEDICATION ACKNOWLEDGEMENT ABSTRACT ABSTRAK

Lecture 9. Semantic Analysis Scoping and Symbol Table

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

SIMS 255 Foundations of Software Design. Complexity and NP-completeness

Composite performance measures in the public sector Rowena Jacobs, Maria Goddard and Peter C. Smith

Programming Languages

Module 11. Software Project Planning. Version 2 CSE IIT, Kharagpur

Image Compression through DCT and Huffman Coding Technique

Applied Algorithm Design Lecture 5

A Model-driven Approach to Predictive Non Functional Analysis of Component-based Systems

So today we shall continue our discussion on the search engines and web crawlers. (Refer Slide Time: 01:02)

CHAPTER 5 STAFFING LEVEL AND COST ANALYSES FOR SOFTWARE DEBUGGING ACTIVITIES THROUGH RATE- BASED SIMULATION APPROACHES

Module 10. Coding and Testing. Version 2 CSE IIT, Kharagpur

Searching Algorithms

Unit 11: Software Metrics

Integer Programming: Algorithms - 3

Using Business Intelligence to Mitigate Graduation Delay Issues

A MULTI-STAGE HEURISTIC APPROACH TO RESOURCE ALLOCATION (AMHARA) FOR AUTOMATED SCHEDULING

CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 313]

VEHICLE ROUTING PROBLEM

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

A Working Knowledge of Computational Complexity for an Optimizer

Using Data Mining for Mobile Communication Clustering and Characterization


Informatica e Sistemi in Tempo Reale

Evaluating the Lead Time Demand Distribution for (r, Q) Policies Under Intermittent Demand

Signal to Noise Instrumental Excel Assignment

SUPPLY CHAIN OPTIMIZATION MODELS IN THE AREA OF OPERATION

A. O. Odior Department of Production Engineering University of Benin, Edo State.

Student Project Allocation Using Integer Programming

Symbol Tables. Introduction

Hardware/Software Co-Design of a Java Virtual Machine

APPROACHES TO SOFTWARE TESTING PROGRAM VERIFICATION AND VALIDATION

Agent Based Decision Support System for Identifying the Spread of Nosocomial Infections in a Rural Hospital

CSC2420 Fall 2012: Algorithm Design, Analysis and Theory

AUTOMATED TEST GENERATION FOR SOFTWARE COMPONENTS

CS Standards Crosswalk: CSTA K-12 Computer Science Standards and Oracle Java Programming (2014)

Logistic Regression for Spam Filtering

Single-Link Failure Detection in All-Optical Networks Using Monitoring Cycles and Paths

Chapter Load Balancing. Approximation Algorithms. Load Balancing. Load Balancing on 2 Machines. Load Balancing: Greedy Scheduling

IMPROVING PERFORMANCE OF RANDOMIZED SIGNATURE SORT USING HASHING AND BITWISE OPERATORS

A METRIC FOR THE ACTIVENESS OF AN OBJECT-ORIENTED COMPONENT LIBRARY

Constraint Programming for Random Testing of a Trading System

Mini-project in TSRT04: Cell Phone Coverage

The Problem of Scheduling Technicians and Interventions in a Telecommunications Company

Chapter 13: Binary and Mixed-Integer Programming

Efficiency of Web Based SAX XML Distributed Processing

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Introduction to Automated Testing

Software Metrics. Lord Kelvin, a physicist. George Miller, a psychologist

Web Mining using Artificial Ant Colonies : A Survey

Solutions to Homework 6

Ian Stewart on Minesweeper

Continuous Fastest Path Planning in Road Networks by Mining Real-Time Traffic Event Information

Load balancing in a heterogeneous computer system by self-organizing Kohonen network

Conditionals (with solutions)

Towards Participatory Design of Multi-agent Approach to Transport Demands

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. #-approximation algorithm.

International Journal of Emerging Technologies in Computational and Applied Sciences (IJETCAS)

Complexity Theory. IE 661: Scheduling Theory Fall 2003 Satyaki Ghosh Dastidar

Stochastic Processes and Queueing Theory used in Cloud Computer Performance Simulations

OPTIMAL VEHICLE TIMETABLING, ROUTING AND DRIVER DUTY SCHEDULING CASE STUDY: BUS DEPOT PROBLEM

How To Get A Computer Science Degree At Appalachian State

Diploma Of Computing

High Performance Computing for Operation Research

MINIMIZING STORAGE COST IN CLOUD COMPUTING ENVIRONMENT

SELECTED ASPECTS OF TRANSPORTATION SYSTEM MODELLING

Term Project: Roulette

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Transcription:

International Journal of Applied Science and Technology Vol. 3 No. 8; December 2013 Evaluation of Complexity of Some Programming Languages on the Travelling Salesman Problem D. R. Aremu O. A. Gbadamosi (Mrs)* Department of Computer Science University of Ilorin Ilorin, Nigeria. Abstract The classical Travelling Salesman Problem and its approximate solution by means of the Nearest Neighbour Heuristic were presented in this study. The objective of the work was to find out the performance of some selected programming languages in solving the TSP. Being an NP- complete problem, it was considered that any means or techniques of reducing the time taken in solving the TSP was a welcome development; hence the need for using very efficient programming languages in developing software having many NP-complete modules cannot be over emphasised. In this study the Nearest Neighbour Heuristic was implemented using C++, C#, and Java. The complexities of the three programs using the Halstead complexities measures were computed. Also, the computer execution times of the three programs were captured. A 10-city TSP was used for illustration. Using the computer execution times, the study showed that both C++ and C# are faster than Java in solving the TSP. The complexities of the C++ programs are the highest, followed by those of C# and Java respectively. These results are in agreement with the fact that C++ is a middle- level language, whereas both C# and Java are higher-level languages. The programming implication of this is that a C++ programmer writes codes more from the scratch than a programmer using C# or Java. The study was concerned only with the classical TSP formulation. Keywords: Complexity, TSP, Halstead Metrics, Computer Execution time 1. Introduction The Travelling salesman problem [TSP] is one of the classical graph problems which still has no practical exact solution; yet it is a model that can be used to represent many real life problems in routing and scheduling in general. It finds relevance in marketing, irrigation, pipe laying, networking, transportation, communication, and so forth. So far heuristics or approximate algorithms are being used to solve those problems that could be modeled as the TSP. Though very simple to characterize it is notoriously difficult to solve; it belongs to the class NPcomplete. It has motivated a number of different approaches, including cutting-plane methods in integer programming, neural nets, simulated annealing and the design of various heuristics [Jonathan L. Gross et.al, 2006]. The TSP naturally arises as a sub-problem in many transportation and logistical problems, for example, the problem of routing of trucks for parcel post pickup, arrangement of school bus routes to pick up the children in a school district, the delivery of meals to homebound person by fast-food firms, and so forth. 2. Motivation and Statement of the Problem 2.1 One of the measures used to evaluate performance of algorithms is the computer time which is a function of programming language, compiler being used, computer hardware and programmer s ability (effectiveness). In recent times, many programming languages are available but little attention is paid to how they perform in the area of software development. However, the development witnessed by the software industry in the recent years has made it imperative for programmers to use efficient programming languages that are easy to understand and implement. Therefore a proper selection of an appropriate language for implementing algorithm is a step in the right direction. This study evaluates the performance of three popular programming languages namely: Java, C++ and C# using the classical Traveling Salesman Problem (TSP) as the problem domain (Fenwa O. D. et. al, 2012). 2.2. Aim and Objectives: The aim of this study is to evaluate the complexity of three different programming languages as tools of implementation, of the Nearest Neighbour Heuristic in solving a typical travelling salesman problem. 52

Center for Promoting Ideas, USA www.ijastnet.com Specially the Objectives are to: i. To use three similar object oriented programming languages in solving TSP. ii. To evaluate the performance of the three languages using Halstead Measure. iii. To evaluate the performance of the three languages using computer execution times. 3. Methodology The Traveling Salesman Problem (TSP) was studied. Arising from the study a 10-city TSP was modeled and a classical heuristic; the Nearest Neighbour Heuristic, was chosen to solve the TSP. The choice of the Nearest Neighbour Heuristic was informed by the fact that it is the most basic and widely used to illustrate the TSP in literature. The Nearest Neighbour Heuristic was programmed using three popular object-oriented programming languages viz: C++, C# and Java. Halstead metrics which measure program complexity directly from the high level implementation (source code) were used to measure the complexity of these languages. Also, the computer execution times were captured and taken into consideration in evaluating the performance of the three languages. Halstead complexity measurement was developed to measure program s complexity directly from source code, with emphasis on computational complexity. The metrics were developed by Maurice Halstead as a means of determining a quantitative measure of complexity directly from operators and operands in the program. Halstead argued that algorithms have measurable characteristics analogous to physical laws. His model is based on four different parameters. 1. The number of distinct operators (instruction types, +, -, /, etc); n 1. 2. The number of distinct operands (variables and constants); n 2. 3. The total number of occurrences of the operators; N 1. 4. The total number of occurrences of the operands; N 2 Using these metrics, the following measures can be computed. 1. Program Length (N) The Program Length (N) is the sum of total number of operators and operands in the program: N = N 1 + N 2 2. Vocabulary Size (n) The Vocabulary Size (n) is the sum of the number of distinct operators and distinct operands: n = n 1 + n 2 3. Program Volume (V) This is the information contents of the program. V = N x log 2 (n) 4. Difficulty Level (D) The difficulty level of a program is proportional to the number of distinct operators in the program. D = (n 1 /2) x (N 2 /n 2 ). 4. Implementation 4.1 Modeling TSP as a Graph A 10-city TSP below was considered and solved using the Nearest Neighbour Heuristic. Three different programming languages were used to implement the Nearest Neighbour method for solving this problem. A complete enumeration solution would give us (n 1)! Solutions generally and in this case it would have given us (10 1)! = (9)! solutions = 181,440 solutions. For a 100-city TSP, we have a solution space that would take the computer running at a speed of computing one solution per microsecond 10 140 centuries (H. P. Williams) A 10-city TSP: A TSP can be modeled as a graph. Figure 4.1 below is a graph of a 10-city TSP. 53

International Journal of Applied Science and Technology Vol. 3 No. 8; December 2013 B C A E D J G F I 54 Fig. 4.1: graph of a 10-city TSP So for pragmatic purposes, getting exact solution is a far cry from practicability, hence the need for making recourse to the use of heuristics. The Nearest Neighbour Heuristics used in this study is as follows. 1. Randomly select a starting node 2. Add to the last node the closest node until no more node is available. 3. Connect the last node with the first node. 4. Stop. The following is the matrix table of the distances between the ten cities. A B C D E F G H I J A 75 30 55 70 70 80 11 40 32 B 75 55 30 40 15 34 22 15 13 C 30 55 65 45 55 21 82 34 34 D 55 30 65 15 120 67 13 22 15 E 70 40 45 15 20 10 51 55 40 F 70 15 55 10 20 12 98 30 21 G 80 34 21 67 10 12 36 75 82 H 11 22 82 13 51 98 36 67 22 I 40 15 34 22 55 30 75 67 20 J 22 13 34 15 40 21 82 22 20 4.2 Halstead Complexity Measurements H Table 4.1 The number of operands and operators present in an algorithm or a computer program are very basic in the bid to calculate the complexity of such a tool. An operand in computer science is the term used to describe any object that is capable of being manipulated. For example, in 1 + 2 the 1 and 2 are operands and the plus symbol is the operator.

Center for Promoting Ideas, USA www.ijastnet.com In addition to digits or letters, operands can also be represented by expressions. A combination of letters, numbers or symbols used to represent a value of a variable is called expression. Expressions are found and used in various programming languages, databases and spreadsheets. Examples are: Sum = zero Minidex = 0 Range = largest smallest Length = matrix.lenght Matrixcol = newint In all the cases above, expressions are the terms to the left and right of the equality symbol. Equality symbol need not always be the operator between expressions. Indeed any operator, formal or informal, can be an operator, operating between expressions. In general operands can be operated upon by more than just one operator. For example: In a + b c; a, b and c are operands while + and are operators. In range = largest smallest, range, largest and smallest are operands while = and are operators. In this study, the following were used as operators =, +, -, >, <, ==,&&, i++, j++, / In computing the complexity, Halstead measures were used. Halstead measures estimate complexity metrics directly from the operators and operands in the source code. The measurable and countable properties are: n 1 = number of unique or distinct operators appearing in the code n 2 = number of unique or distinct operands appearing in the code N 1 = number of all the operators appearing in the code N 2 = total number of all the operands appearing in the code. From these metrics, Halstead defines The vocabulary (n) as n = n 1 + n 2 The program length (N) as N = N 1 + N 2 The following complexities were then calculated (i) Program length (N) = N 1 + N 2 (ii) Vocabulary size (n) = n 1 + n 2 (iii) Volume (V) = N x log 2 (n) (iv) Difficulty level (D) = (n 1 /2) x (N 2 /n 2 ) 55

International Journal of Applied Science and Technology Vol. 3 No. 8; December 2013 4.3 Overall Control Structure The following algorithm depicts the overall structure of the three programs. 56 Begin End Initialise All Variables Supply Input Data Begin End; Repeat Read input data Until all data are read Start with an arbitrary node Begin End; 5. Analysis of Results Repeat Visit the Nearest Node recursively Until all nodes have been visited Join the last node with the first node The results obtained from our implementation detailed in section (4) are presented and discussed in this section. 5.1 Computing the Complexities In computing the complexities, the declaration part, the input part as well as the output part of the three programs are not taken into consideration. This is informed by the fact that these three parts constitute basically the main housekeeping functions in running any program on the computer. It is considered that the major differences in the complexities of the program would be implicit in the actual computation peculiar to each program. The following metrics are derived by counting n 1, n 2, N 1, N 2 and manipulating them with respect to each of the three programs. 5.1.1 Analysis of the C++ program (a) From int arraymin (int arr [ ]) module: number of distinct operators n 1 = 6 number of distinct operands n 2 = 10 number of all operators N 1 =13 number of all operands N 2 = 25

Center for Promoting Ideas, USA www.ijastnet.com (b) From int main ( ) module: number of distinct operators n 1 = 3 number of distinct operands n 2 = 10 number of all operators N 1 =8 number of all operands N 2 = 14 (c) From the entire program number of distinct operators n 1 = 6 + 3 = 9 number of distinct operands n 2 = 10 +10 = 20 number of all operators N 1 =13 + 8 =21 number of all operands N 2 = 25 +14 = 39 Hence (i) Program length (N) = N 1 + N 2 = 21 + 39 = 60 (ii) Vocabulary size (n) = n 1 + n 2 = 9 + 20 = 29 (iii) Volume (V) = 60log 2 29 (iv) Difficulty level (D) = (n 1 /2) x (N 2 /n 2 ) = (9/2) x 39/20 = 8.775 5.1.2 Analysis of C# program number of distinct operators n 1 = 6 number of distinct operands n 2 = 13 number of all operators N 1 = 21 number of all operands N 2 = 37 Hence (i) Program length (N) = N 1 + N 2 = 21 + 37 = 58 (ii) Vocabulary size (n) = n 1 + n 2 = 6 + 13 = 19 (iii) Volume (V) = Nlog 2 n = 58log 2 19 (iv) Difficulty level (D) = (n 1 /2) x (N 2 /n 2 ) = (6/2) x 37/13 = 8.538 5.1.3 Analysis of Java program number of distinct operators n 1 = 7 number of distinct operands n 2 = 12 number of all operators N 1 = 21 number of all operands N 2 = 35 Hence (i) Program length (N) = N 1 + N 2 = 21 + 35= 56 (ii) Vocabulary size (n) = n 1 + n 2 = 7 + 12 = 19 (iii) Volume (V) = Nlog 2 n = 56log 2 19 (iv) Difficulty level (D) = (n 1 /2)x(N 2 /n 2 ) = (7/2) x 35/12 = 10.208 5.2 Results and Discussion Table 4.6: Results: complexities and computer execution times. Program length Vocabulary size Volume Difficulty level Computer execution time (nano sec.) N N V D C++ 60 29 60log 2 29 8.775 0.0000 C# 58 19 58log 2 19 8.538 0.0000 Java 56 19 56log 2 19 10.208 1337 From our results above, we have the following order: Program length N: Java < C# < C++ 57

International Journal of Applied Science and Technology Vol. 3 No. 8; December 2013 Vocabulary V: (Java = C#) < C++ Program Volume V: Java < C# < C++ Difficulty level D: C# < C++ < Java Computer Execution Times in Nanoseconds: (C++ = C#) < Java First and foremost we must understand the basic differences between C++, C# and Java. Such an understanding will inform our opinion about the behaviour of these languages vis-a-vis the programs we analyzed. First, Java is a general-purpose, concurrent, class-based, Object-oriented computer programming language that is specifically designed to have as few implementation dependences as possible. It is intended to let application developers, write once, run anywhere (WORA) meaning that code that runs on one platform does not need to be recompiled to run on another. Java is one of the most popular programming languages in use, particularly for client server web applications. However, the following criticisms have been directed at Java. Its speed of executing program is slower compared to that of other object-oriented programming languages. Also, it has a history of security vulnerabilities in the primary java virtual machine implementation. C# on the other hand aims to combine the high productivity of Visual Basic and the power of C++. It was designed specifically to work with the.net and is geared to the modern environment of windows and mousecontrolled user interface, networks and the internet. C++ however was designed to be a mid-level platform-neutral object-oriented programming language. A C++ programmer would do more coding form the scratch than a programmer in C# or Java. i. From the foregoing therefore, it should not be surprising that both C++ and C# performed better in terms of computer execution times. The time taken by both C++ and C# could not even be measured in nanoseconds; this explains why their computer execution times were zero. Whereas the time taken by Java was 1337 nanoseconds. This confirmed the speed weakness already levied against Java. ii. The complexities of the C++ program in terms of program length, program vocabulary and program volume are more than those recorded for C# and Java. This also confirms the claim that whereas both C# and Java are higher-level language, C++ is a mid-level language which naturally requires more effort in coding. iii. In terms of program difficulty, both C++ and C# behave approximately alike with complexities of 8.775 and 8.538 respectively, while Java has a difficulty level of 10.208. An objective and reliable meaning of these metrics is that both C++ and C# could be classified as requiring roughly the same programmers effort while Java requires a different effort. These results are not sufficient to conclude that Java is more difficult than C++ and C# and vice-versa. More factors will have to be considered in arriving at such a conclusion. iv. Finally, considering the fact that the Traveling Salesman Problem is an NP-complete problem, any device or effort that could reduce the time required in solving the problem should be embraced. From our results, it is very clear that though Java has become the most popular programming language, it should not be used in designing software for solving NP-complete problems. As shown by the results in this study, C++ and C# are preferred when the speed of computation is of paramount importance. 6. Conclusion This study examines the performance of three programming languages viz: C++, C#, and Java in solving the travelling salesman problem using the nearest neighbour heuristic. In addition it also evaluates the performance of these languages using computer execution time. The complexities of the programs written in these languages were computed using the Halstead metrics: Program Length, Vocabulary Size, Program Volume, and Difficulty Level. Our results showed that both C++ and C# are faster than Java in solving the TSP; also the complexities of C++ are highest. The programming implication of this is that a C++ programmer will have to write codes more from the scratch than a programmer using C# and Java. This is in line with the fact that C++ is a middle-level language, whereas both C# and Java are higher-level languages. 58

Center for Promoting Ideas, USA www.ijastnet.com Furthermore, both C++ and C# took approximately the same computer time to execute and get the output, Java took by far higher computer time, that is, Java is slower in speed than both C++ and C#. This also corroborates the known characteristic of Java as a relatively slow language. One of the limitations of this study is that the TSP considered in this work was solved statically; another limitation is that this study assumed that it would always be possible for our hypothetical salesman to be moving to the nearest nodes. Apparently, it may not be possible in real life due to some unforeseen constraints to move always to the nearest nodes. Hence, while recommending that for a future research the TSP could be solved dynamically to make room for flexibility in the number of cities that this framework could accommodate, it is also recommended that situations whereby it becomes impossible to move to the nearest nodes, should be another candidate that can be considered in future research. References Fenwa O.D; Okeyinka A. E; Olabiyisi S.O, and Ajala F.A. (2012); Performance Evaluation of Implementation Languages on the Complexity of Heapsort Algorithm; International Journal of Computer Application; Issue 2 Volume 5, October 2012. H.P. Williams The Traveling Salesman Problem, London School of Economics. National Open University of Nigeria (2006); Lecture Notes on Object- Oriented Programming. Okediran O. O, 2008. A performance Evaluation of Selected Heuristics to Travelling Salesman Problem. S.E. Goodman and S.T. Hedetniemi (1997); Introduction to the Design and Analysis of Algorithms; McGraw Hill Ltd. 59