Top Banner
VISA Algorithm Visualization
39

VISA

Aug 07, 2015

Download

Documents

3ashmawy
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: VISA

VISA

Algorithm Visualization

Page 2: VISA

What is VISA ?

• VISA is an algorithm visualization tool that could be used to visualize arbitrary algorithms.

• The system relies on JDI (Java Debugging Interface) to dynamically extract information from the virtual machine.

Page 3: VISA

Who are the system users ?

• User/Viewer– The person that will use the system to select from

an algorithm collection an algorithm to run and then watch the visualization to understand how the algorithm behaves.

• Programmer– The person that should write the algorithm and

visualization code that will be executed by the user/viewer.

Page 4: VISA

System Functionalities

Functionalities

Viewer Programmer

Page 5: VISA

Viewer Trace Table

Input Graphical Interface

Console PanelCode View

Control Panel

Visualization

Trace Table Displays data values

Local Variables Method Arguments (Optional) Fields

Modification Highlighting Threads Aware

public static boolean BSearch(index low, index high) {index mid;if (low > high) then return False;else{ mid = b(low + high)/2; if (x == S[mid]) then return True; else if (x < S[mid]) then

return BSearch(low, mid−1); else

return BSearch(mid+1, high);}

}

Page 6: VISA

Viewer• Input Graphical Interface

– Field types– Randomizing Values– Restrictions

• Primitive Types• Arrays• Single threaded • Fields only

Trace Table

Input Graphical Interface

Console PanelCode View

Control Panel

Visualization

get values for Name, Names1, ...,NamesN, Phones1, ..., PhonesNset i to 1set Found to NOrepeat if Name = Ni then print the value of Ti set Found to YES else set i to i+1 endifuntil found = YES or i>1000if Found = NO then print “sorry, name is not in directory”endif

Page 7: VISA

Viewer

• Console Panel– Input Stream– Output Stream– Error Stream

Trace Table

Input Graphical Interface

Console Panel

Code View

Control Panel

Visualization

System.out.println(“Please Enter Type: ”);try{ type = stdin.readLine();}catch(Exception e){ e.printStackTrace();}

Page 8: VISA

Viewer

• Code View– Pseudo code of algorithm– Current executing statement

highlighting

Trace Table

Input Graphical Interface

Console Panel

Code View

Control Panel

Visualization

Page 9: VISA

ViewerTrace Table

Input Graphical Interface

Console PanelCode View

Control Panel

Visualization

Control PanelContinuous executionSteppingPausingRestarting

Page 10: VISA

Viewer

• Visualization– Displays the algorithm

visualization depending on the actual execution

Trace Table

Input Graphical Interface

Console PanelCode View

Control Panel

Visualization

int fibRec(int n){ if (n == 1 || n == 2) then return 1; else return fibRec(n-1) + fibRec(n-2); }

Page 11: VISA

Viewer

• Other– Delay time– Number of operations– Watching arguments

Page 12: VISA

Programmer

• Role of programmer– Pseudo code file• The text file that will contain

the pseudo code of the algorithm to be executed

Pseudo code File

Algorithm ClassMap File

Visualization Class

int fibRec(int n){ if (n == 1 || n == 2) then return 1; else return fibRec(n-1) + fibRec(n-2); }

Page 13: VISA

Programmer

• Role of programmer– Algorithm class• Java Implementation of the

algorithm

Pseudo code File

Algorithm Class

Map File

Visualization Class

public class RecursiveFibonacci {

public static int fibRec(int n) { if(n==1 || n==2){ return 1; }else{ return fibRec(n-1)+fibRec(n-2); } } }

Page 14: VISA

Programmer• Role of programmer

– Map File• The map file is where the mapping between

the pseudo code and the Java code is defined.

Pseudo code File

Algorithm Class

Map File

Visualization Class

1: int fibRec(int n){2: if (n == 1 || n == 2) then3: return 1;4: else5: return fibRec(n-1) + fibRec(n-2);6: }

1: public class RecursiveFibonacci {2:3: public static int fibRec(int n)4: {5: if(n==1 || n==2){6: return 1;7: }else{8: return fibRec(n-1)+fibRec(n-2);9: }10: }11: 12: }

1:3;2:5;3:6;4:7;5:8;6:9;

Page 15: VISA

Programmer• Role of programmer– Visualization class

• The class that should be written by the programmer to define how the algorithm animation will be produced.

• In comparison with other systems– Java vs. Custom language– Selection of any Java visual library vs. Using only

the developer’s visual library

• Restrictions– Extends the class Component– Implements the interface VisualInterface

Pseudo code File

Algorithm ClassMap File

Visualization Class

Page 16: VISA

Programmer

• Role of programmer– Visualization class• Implements the interface VisualInterface

– Implement the following methods» void LocalVariableCreated(LocalVariableEvent event)

» void localVariableModified(LocalVariableEvent event)

» void fieldAction(FieldEvent event)» void methodEntry(MethodEntryEvent event)» void methodExit(MethodExitEvent event)» void threadStarted(ThreadStartEvent event)» void threadDied(ThreadDeathEvent event)

Pseudo code File

Algorithm ClassMap File

Visualization Class

Page 17: VISA

Programmer

• Annotations– Java annotations are metadata that could be

added to Java source code – Retrievable at run time– Uses• Information for the compiler• Code generation• Run time processing

Page 18: VISA

Programmer• VISA annotations– @GetInput• Used to declare that a specific

field should receive its value from Graphical input interface• Example

@GetInput String name;

@GetInput

@VisualizationClass

@RandomFile

Page 19: VISA

Programmer

• VISA annotations– @VisualizationClass• Used to declare that a specific

algorithm class should be visualized by a certain visualization class

@GetInput

@VisualizationClass

@RandomFile

○ Example@VisualizationClass(fileName="BinarySearchVisual")public class BinarySearch{

…}

Page 20: VISA

Programmer

• VISA annotations– @RandomFile• Used to declare that a certain

field should acquire its random values from a specific file• Restrictions

– Must be annotated by @GetInput as well

• Example@GetInput(field="null")

@RandomFile(file="names.random") String name

@GetInput

@VisualizationClass

@RandomFile

Page 21: VISA

Programmer

• VISA files hierarchy

VISA Executable

JAR

VISACompressed

File

VISA

algorithms

code CS102 Analysis & DesignOf Algorithms

CClass File

CClass File

JJava File

…M

BinarySearch.map

PS

BinarySearch.txt

……

IterativeConditional

Page 22: VISA

System Implementation

Controller

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Debugging Engine

Virtual Machine

Page 23: VISA

System Implementation

Controller

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Virtual Machine

Debugging Engine

Event Request Manager

Class Prepare Events

Method Entry/Exit Events

Thread Start/Death Events

Step Events

VM Mirror

VM Connector

Page 24: VISA

System Implementation

Controller

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Debugging Engine

VM Mirror

Event Queue

Receive Events

Virtual Machine

Threads

ThreadReference ThreadTrace

…. ….

Main thread

Thread Started Event

Other threads

Page 25: VISA

System Implementation

Controller

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Debugging EngineVM

Mirror

Event Queue

Receive Events

Virtual Machine

Class Prepare Event

Fields

Request Modification Watch Events

LoadingVerification Preparation Resolution

Linking

Event Request Manager

Modification Watch Event

Create Field Action Events

Page 26: VISA

System Implementation

Controller

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Debugging EngineVM

Mirror

Event Queue

Receive Events

Virtual Machine

Local variables Step Event

Method Invoked

New Frame Execute

Statements

Stack Frame

Stack Frame

Current Frame

Local Variables

….

Local Variable Created Event

Local Variable Modified Event

Page 27: VISA

System Implementation

Controller

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Virtual Machine

Debugging EngineVM

Mirror

Event Queue

Receive Events

Thread Start Event

Thread Death Event

Method Entry Event

Method Exit Event

Page 28: VISA

System Implementation

Debugging Engine

Virtual Machine

Controller

VM Process

InputStream

OutputStream

ErrorStream

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Page 29: VISA

System Implementation

Controller

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Debugging Engine

Virtual Machine

Console Panel

InputStream

OutputStream

ErrorStream

Key Listener

Text Area

Page 30: VISA

System Implementation

Debugging Engine

Virtual Machine

Controller

Algorithm

Binary Search

Map File Pseudo Code File

Executed Java Line

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Page 31: VISA

System Implementation

Controller

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Debugging Engine

Virtual Machine

Console Panel

Code Control

Map File

Pseudo code File

Map Vector

Pseudo code line #

Java Line Vector

Each entry contains Java line #

Executed Java Line

Highlight Equivalent

Pseudo code Line

Text Area

Page 32: VISA

System Implementation

Debugging Engine

Virtual Machine

Controller

Method Entry

Method Exit

Thread Start

Thread Death

Local Variable Created

Local Variable Modified

Field Action

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

@VisualizationClass Found

Algorithm Class

Page 33: VISA

System Implementation

Controller

Code Control

Annotation Processor

Trace Table

Input Graphical Interface

Debugging Engine

Virtual Machine

Console PanelVisualization System

@VisualizationClass Found Visualization class

Extends Component Check

Implements VisualInterface

Check

Load & Execute Visualization class

constructor

Method Entry

Method Exit

Thread Start

Thread Death

Local Variable Created

Local Variable Modified

Field Action

Executing Visualization

class

Page 34: VISA

System Implementation

Debugging Engine

Virtual Machine

Controller

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Variable Table Location

… …

Statement Executed

Variable Already In

Table ?

Yes No

Update Table

Highlight Line

Add new Row

Page 35: VISA

System Implementation

Controller

Code Control

Visualization System

Annotation Processor

Input Graphical Interface

Debugging Engine

Virtual Machine

Console Panel

Trace Table

Highlight Line

Add new Row

JTable

Page 36: VISA

System Implementation

Debugging Engine

Virtual Machine

Controller

Console Panel

Code Control

Visualization System

Annotation Processor

Trace Table

Input Graphical Interface

Thread Started

Algorithm Class

Fields Annotated

Pause

Fields Values

Resume

Page 37: VISA

System Implementation

Controller

Code Control

Visualization System

Annotation Processor

Debugging Engine

Virtual Machine

Console Panel

Trace Table

Input Graphical Interface

Fields Annotated

JPanel

Field values

Page 38: VISA

System Implementation

Controller

Code Control

Visualization System

Debugging Engine

Virtual Machine

Console Panel

Trace Table

Input graphical interface

Annotation processor

Thread Started

Algorithm Class

Start Working

@VisualizationClass annotations

@GetInput annotations

@RandomFile annotations

Fields declared

Page 39: VISA

Demo