27-Oct-15 Graphs and Hypergraphs. Graph definitions A directed graph consists of zero or more nodes and zero or more edges An edge connects an origin.

Slides:



Advertisements
Similar presentations
Chapter 7. Binary Search Trees
Advertisements

Generics, Lists, Interfaces
Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view class.
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
Priority Queues. 2 Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out The “smallest” element.
Representing Relations Using Matrices
23-May-15 Polymorphism. 2 Signatures In any programming language, a signature is what distinguishes one function or method from another In C, every function.
CS102--Object Oriented Programming Lecture 17: – Linked Lists Copyright © 2008 Xiaoyan Li.
Abstract Data Types II. 2 Sufficient operations Operations on an ADT are sufficient if they meet all the requirements They must be able to create all.
hashing1 Hashing It’s not just for breakfast anymore!
Spanning Trees.
hashing1 Hashing It’s not just for breakfast anymore!
1 Java Object Model Part 2: the Object class. 2 Object class Superclass for all Java classes Any class without explicit extends clause is a direct subclass.
Abstract Data Types II. 2 Sufficient operations Operations on an ADT are sufficient if they meet all the requirements They must be able to create all.
Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
Searching. 2 Searching an array of integers If an array is not sorted, there is no better algorithm than linear search for finding an element in it static.
Abstract Data Types II. Sufficient operations Operations on an ADT are sufficient if they meet all the requirements –They must be able to create all the.
13-Jul-15 Abstract Data Types. 2 Data types I We type data--classify it into various categories-- such as int, boolean, String, Applet A data type represents.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
Chapter 7 More Lists. Chapter 7: More Lists 7.1 – Circular Linked Lists 7.2 – Doubly Linked Lists 7.3 – Linked Lists with Headers and Trailers 7.4 – A.
Unit 11, Part 2: Introduction To Logarithms. Logarithms were originally developed to simplify complex arithmetic calculations. They were designed to transform.
AITI Lecture 20 Trees, Binary Search Trees Adapted from MIT Course 1.00 Spring 2003 Lecture 28 and Tutorial Note 10 (Teachers: Please do not erase the.
Data structures and algorithms in the collection framework 1 Part 2.
The Java Collections Framework (Part 2) By the end of this lecture you should be able to: Use the HashMap class to store objects in a map; Create objects.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Graphs. 2 Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Chapter 18 Java Collections Framework
13-1 Sets, Bags, and Tables Exam 1 due Friday, March 16 Wellesley College CS230 Lecture 13 Thursday, March 15 Handout #23.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
HashCode() 1  if you override equals() you must override hashCode()  otherwise, the hashed containers won't work properly  recall that we did not override.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Comparable and Comparator Nuts and Bolts. Sets A set is a collection in which all elements are unique—an element is either in the set, or it isn’t In.
Chapter 1: Object Oriented Paradigm. 1.1 Data Abstraction and Encapsulation OOP allows programmer to – separate the details that are important to the.
23-Dec-15 Graphs and Hypergraphs. Graph definitions A directed graph consists of zero or more nodes and zero or more edges An edge connects an origin.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
COMP 121 Week 8: Generic Collections. Objectives To understand type variables and how they are used in generic programming To be able to implement and.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Copyright © Curt Hill Graphs Definitions and Implementations.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
OOP Basics Classes & Methods (c) IDMS/SQL News
Lecture 16 Linked Lists. In this lecture Fundamentals Applications Memory Allocation Creating a List Inserting Nodes.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
Important Annoucement 1  I messed up something in the last class  if a subclass overrides a method that throws an exception then it must either 1. throw.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 7: A Tale of Two Graphs (and.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
LINKED LISTS.
Searching.
The StringBuffer Class 
Abstract Data Types II.
Graphs and Hypergraphs
Phil Tayco Slide version 1.0 Created Oct 9, 2017
3.5 Minimum Cuts in Undirected Graphs
Spanning Trees.
Graphs.
Graph API (How I Did It) 1-Jan-19.
Graphs and Hypergraphs
Searching.
CS2013 Lecture 7 John Hurley Cal State LA.
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
CMPE212 – Reminders Assignment 2 due next Friday.
Chapter 3: Multivalued Dependencies
Presentation transcript:

27-Oct-15 Graphs and Hypergraphs

Graph definitions A directed graph consists of zero or more nodes and zero or more edges An edge connects an origin node to a destination node The origin and destination nodes need not be distinct, but they must be on the same graph An undirected graph can be represented as a directed graph in which all edges come in pairs

APIs for ADTs Requirements of an API: The constructors and transformers must together be able to create all legal values of the ADT Or, at least, any needed by the applications that use it For a general use ADT, this means all legal values The accessors must be able to extract any data Or, at least, any needed by the applications that use it Desirable properties of an API: The API should be simple Convenience methods should be provided if: They are likely to be used often The user would expect them to be present (e.g. toString() ) They simplify the use of the API more than they add complexity to it They provide serious gains in efficiency

My graph API In my design: There are three classes: Graph, Node, and Edge The Graph class has a print() method My goals for my design were completeness and simplicity (in that order) I am not claiming that my design is the best possible, but I think it’s very good

Graph methods Constructor public Graph(Object value) Mutative transformers public void delete(Node node) public void delete(Edge edge) Accessors public Set public String toString() public void print() public void dump() // debugging aid

Node methods Constructor public Node(Object value, Graph g) Mutative transformer public void delete() Accessors public Graph getGraph() public Set getOutpointingEdges() public Set public String toString()

Edge methods Constructor public Edge(Node fromNode, Object value, Node toNode) Mutative transformer public void delete() Accessors public Graph getGraph() public Node getOrigin() public Node public String toString()

Where is...? Where’s the data? (Node names, edge labels, etc.) My classes all extend Plex, which contains Object value Plex has getValue and setValue methods Where are the equals(Object obj) methods? I claim node equality means: Same node, same graph. In other words, == Similarly for edges Equality for graphs could mean graph isomorphism: There exist Node G1  Node G2 and Edge G1  Edge G2 mappings that make the graphs have identical structure This is an intractable (exponential) problem, and I don’t deal with it Where are the hashCode() methods? The inherited hashCode methods are consistent with equals meaning == Where are the applicative transformers? I couldn’t see any use for them They’re easy enough for the user to write

Why do I have...? A deleteEdge(Edge edge) method in Graph, when I already have a delete() method in Edge ? It’s just a convenience method Since I have deleteNode (which is necessary), it’s reasonable for the user to expect a corresponding deleteEdge method A getInpointingEdges() in Node ? Most programs only use outpointing edges If the method is needed, it’s easy for me to provide, much much more complex for the user All those toString() methods? I think toString() is always a good idea—for debugging, if nothing else

Hypergraphs A hypergraph is a collection of zero or more graphs, with many fewer restrictions. There is no generally accepted definition of a hypergraph, but here are some of the things that might be allowed Nodes may reside simultaneously on many graphs, or on none at all Edges may originate from multiple nodes, or none at all Edges may terminate at (point to) multiple nodes, or none at all The origin and destination nodes of an edge need not be on the same graph Edges may originate from and/or point to graphs or other edges Graphs may contain other graphs as nodes. Nodes may contain graphs Even edges may contain graphs Obviously, a hypergraph is a much more complex structure than a simple directed graph With the right approach, hypergraphs are actually much simpler than “ordinary” graphs

Plex I don’t know where the notion of a plex came from You won’t find this term in the literature A plex consists of four sets: containers: The other plexes in which this plex occurs For example, nodes and arcs may occur in a graph contents: The other plexes contained in this plex For example, a graph may contain nodes and arcs origins: The other plexes “from which” this plex comes For example, an edge comes from a node destinations: The other plexes “to which” this plex goes For example, an edge goes to a node There are two simple validity rules: If plex X is a container of plex Y, then plex Y is a content of plex X, and vice versa If plex X is a destination of plex Y, then plex Y is an origin of plex X, and vice versa This redundancy is for reasons of efficiency

Validity Rules Plex1 contains Plex2 Plex2 is contained in Plex1 Plex4 is an origin of Plex3 Plex3 is a destination of Plex4

Plex data and constructors public class Plex { Set containers = new HashSet (); Set contents = new HashSet (); Set origins = new HashSet (); Set destinations = new HashSet (); public Object value; protected Plex() { } protected Plex(Object value) { this.value = value; }

Plex methods Similarly for addContent, removeContent, addOrigin, removeOrigin, addDestination, and removeDestination void addContainer(Plex that) { this.containers.add(that); that.contents.add(this); } void removeContainer(Plex that) { this.containers.remove(that); that.contents.remove(this); }

Implementing hypergraphs with plexes A plex can represent a graph Its contents can hold the nodes on this graph A plex can represent a node Its containers can hold the graph(s) on which it occurs Its origins can hold its inpointing edges Its destinations can hold its outpointing edges A plex can represent an edge Its containers can hold the graph(s) on which it occurs Its origins can hold its origin node(s) Its destinations can hold its destination node(s) Aside from what we call things, once we have implemented plexes, we have implemented hypergraphs!

Implementing graphs with plexes We can model graphs, nodes, and edges by putting restrictions on their plexes Graph: The origins, destinations, and containers sets are empty The nodes of the graph are in the contents set Node: The contents set is empty The containers set contains a single element, the graph that the node resides on The origins set contains the edges that point to the node The destinations set contains the edges that come out of the node. Edge: The contents set is empty The containers set contains only the graph that the edge resides on The origins set contains only the one node from which the edge originates The destinations set contains only the one node that the edge points to

A slightly amusing helper method Suppose you have a Set containing at most one element--how do you get that element? class Extractor { protected static Plex getOne(Set set) { for (Plex plex : set) { return plex; } return null; } }

Deep Thoughts Probably the earliest flyswatters were nothing more than some sort of striking surface attached to the end of a long stick. -- Jack Handy If I had a mine shaft, I don't think I would just abandon it. There's got to be a better way. -- Jack Handy The data structure you choose can make a huge difference in the complexity of your program. -- me

The End