Ideas for testing Transformations of cds 4/27/2019 AOO/Demeter.

Slides:



Advertisements
Similar presentations
Models of Computation Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms Week 1, Lecture 2.
Advertisements

Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Lecture 24 MAS 714 Hartmut Klauck
JAYASRI JETTI CHINMAYA KRISHNA SURYADEVARA
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Great Theoretical Ideas in Computer Science for Some.
CSC5160 Topics in Algorithms Tutorial 2 Introduction to NP-Complete Problems Feb Jerry Le
Computability and Complexity 13-1 Computability and Complexity Andrei Bulatov The Class NP.
1 Lecture 4 Topics –Problem solving Subroutine Theme –REC language class The class of solvable problems Closure properties.
The Theory of NP-Completeness
Chapter 11: Limitations of Algorithmic Power
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 22 Instructor: Paul Beame.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Hardness Results for Problems
Chapter 11 Limitations of Algorithm Power. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples:
CSCE350 Algorithms and Data Structure
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 11 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Theory of Computation, Feodor F. Dragan, Kent State University 1 NP-Completeness P: is the set of decision problems (or languages) that are solvable in.
The Complexity of Optimization Problems. Summary -Complexity of algorithms and problems -Complexity classes: P and NP -Reducibility -Karp reducibility.
NP Complexity By Mussie Araya. What is NP Complexity? Formal Definition: NP is the set of decision problems solvable in polynomial time by a non- deterministic.
TECH Computer Science NP-Complete Problems Problems  Abstract Problems  Decision Problem, Optimal value, Optimal solution  Encodings  //Data Structure.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
Design and Analysis of Algorithms - Chapter 101 Our old list of problems b Sorting b Searching b Shortest paths in a graph b Minimum spanning tree b Primality.
NP-Completeness (Nondeterministic Polynomial Completeness) Sushanth Sivaram Vallath & Z. Joseph.
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 30, 2014.
NPC.
Young CS 331 D&A of Algo. NP-Completeness1 NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and.
Introduction to NP Instructor: Neelima Gupta 1.
1 1. Which of these sequences correspond to Hamilton cycles in the graph? (a) (b) (c) (d) (e)
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Approximation algorithms
CSC 421: Algorithm Design Analysis
The Theory of NP-Completeness
The NP class. NP-completeness
NP-Complete Problems.
More NP-Complete and NP-hard Problems
Graphs 4/13/2018 5:25 AM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 NP-Completeness.
Chapter 10 NP-Complete Problems.
Lecture 7: Constrained Conditional Models
NP-Completeness NP-Completeness Graphs 5/7/ :49 PM x x x x x x x
Chapter 12: Theory of Computation
Introduction to Randomized Algorithms and the Probabilistic Method
Richard Anderson Lectures NP-Completeness
Great Theoretical Ideas in Computer Science
Hard Problems Introduction to NP
Lecture 8 Style rules: Class graph minimization
NP-Completeness Yin Tat Lee
Intro to Theory of Computation
NP-Completeness NP-Completeness Graphs 11/16/2018 2:32 AM x x x x x x
Analysis and design of algorithm
Richard Anderson Lecture 25 NP-Completeness
How Hard Can It Be?.
NP-Completeness NP-Completeness Graphs 12/3/2018 2:46 AM x x x x x x x
CLASSES P AND NP.
Chapter 11 Limitations of Algorithm Power
CSC 4170 Theory of Computation The class NP Section 7.3.
NP-Completeness Yin Tat Lee
NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979.
The Theory of NP-Completeness
Trevor Brown DC 2338, Office hour M3-4pm
CSE 589 Applied Algorithms Spring 1999
Dichotomies in CSP Karl Lieberherr inspired by the paper:
ICS 353: Design and Analysis of Algorithms
Instructor: Aaron Roth
Instructor: Aaron Roth
Our old list of problems
Presentation transcript:

Ideas for testing Transformations of cds 4/27/2019 AOO/Demeter

Algorithmical/theoretical nuggets Software development is a hard problem. Pick out well-defined subproblems which can be solved algorithmically or which can at least be understood better. E.g. class dictionary minimization/transformation programming traversals class graph learning strategy minimization 4/27/2019 AOO/Demeter

Equivalences between class dictionaries Use them for testing 4/27/2019 AOO/Demeter

Class graph minimization Definition: size of class graph = number of construction edges + 1/4 * number of alternation edges Why 1/4? encourage use of inheritance, factoring out commonality is good! simplifies algorithm, any constant < 1/2 also works. 4/27/2019 AOO/Demeter

Class graph minimization Fruit : Apple | Orange *common* Weight. Apple=. Orange=. 1 + 0.5 = 1.5 (1+2=3) Apple = Weight. Orange = Weight. 2 w w w 4/27/2019 AOO/Demeter

Class graph minimization Problem: input: class graph G output: class graph H of minimum size and object-equivalent to G An NP-hard minimization problem: at least as hard as any problem in NP. 4/27/2019 AOO/Demeter

Complexity theory excursion Problem kinds: decision problems: Is x in X? optimization problem (considered here): For x in X find smallest (largest) element y in X with property p(x, y). Decision problems: Is Boolean formula always true? Is class dictionary ambiguous? Are two class graphs object-equivalent? 4/27/2019 AOO/Demeter

Levels of algorithmic difficulty Unsolvable: no algorithm exists Is class dictionary ambiguous? Define 2 class dictionnaries the same language? Only slowly solvable (no polynomial-time algorithm exists or is currently known) Is Boolean formula always true? (co-NP hard) Efficiently solvable (polynomial-time) Are two class graphs object-equivalent? 4/27/2019 AOO/Demeter

Word of caution Complexity theory is an asymptotic theory. All algorithmic problems of finite size can be solved by a computer (Turing machine). But all practical algorithmic problems are of finite size. Complexity theory still practically very useful: It guides your search for algorithms. 4/27/2019 AOO/Demeter

Other NP-hard problems Has a Boolean formula a satisfying truth assignment? (in NP, hence NP-complete) Exists there a class graph x which is object-equivalent to y but of smaller size? (in NP) Can we color the nodes of a class graph with three colors so that no two adjacent nodes have the same color. (in NP) Strategy minimization (class graph known). 4/27/2019 AOO/Demeter

Why are they all NP-hard? They can be reduced to one another by polynomial transformations similar to the transformations: A class graph which is not flat can be transformed into an object-equivalent one which is flat and by at most squaring the size. Law of Demeter transformation: a program which violates LoD can be transformed to satisfy LoD with small increase in size. 4/27/2019 AOO/Demeter

Class graph minimization Focus on class graphs allowed by single inheritance languages, like Java and Smalltalk. Definition: A class graph is single-inheritance if each class has at most one incoming subclass edge. Problem: Is there an object-equivalent class graph G’ for G which is single inheritance? 4/27/2019 AOO/Demeter

Class graph minimization ChessPiece : Queen | King | Rook | Bishop | Knight | Pawn. Officer : Queen | King | Rook. ChessPiece : Officer | Class graph becomes single inheritance, Object-equivalence preserved. 4/27/2019 AOO/Demeter

Class graph minimization ChessPiece : Queen | King | Rook | Bishop | Knight | Pawn. Officer : Queen | King | Rook. ChessPiece : Officer | B Knight P Q K R 4/27/2019 AOO/Demeter

Requires multiple inheritance? RadiusRelated : Coin | Sphere *common* Radius. HeightRelated : Brick | Sphere *common* Height. Why? not all or nothing. R H C R S H B C B S 4/27/2019 AOO/Demeter

Tree property - all or nothing yes no A collection of subsets of a set satisfies the tree property, if for any two subsets either one contains the other or the two are disjoint. 4/27/2019 AOO/Demeter

From multiple to single inheritance G is object-equivalent to a single-inheritance class graph if and only if the collection of concrete subclass sets of G satisfies the tree property. The collection of concrete subclass sets of G is the collection of subsets consisting of all concrete subclasses of classes in G. 4/27/2019 AOO/Demeter

Algorithm Containment relationships between subclass sets determine single inheritance structure. x1 A B C D x2 x3 x2 x3 E F x1 A B C E F D 4/27/2019 AOO/Demeter

Class graph minimization Problem: NP-hard input: class graph G output: class graph H of minimum size and object-equivalent to G Problem: Polynomial output: class graph H with minimum number of construction edges and object-equivalent to G 4/27/2019 AOO/Demeter

Class graph minimization Achieve in two steps: Minimize number of construction edges (polynomial) alternation edges (NP-hard) 4/27/2019 AOO/Demeter

Class graph minimization/ construction edge minimization A construction edge with label x and target v is redundant if there is a second construction edge with label x and target w such that v and w have the same set of subclasses. x x x w x 4/27/2019 AOO/Demeter v v=w

Class graph minimization/ construction edge minimization x x x w v x x x v=w x x w v 4/27/2019 AOO/Demeter

Class graph minimization/ construction edge minimization Abstraction of common parts solves construction edge minimization problem: Are there any redundant parts? yes: attach them to an abstract class, introduce a new one if none exists. no: minimum achieved x x v=w 4/27/2019 AOO/Demeter

Recall: Class graph minimization Definition: size of class graph = number of construction edges + 1/4 * number of alternation edges Why 1/4? encourage use of inheritance, factoring out commonality is good! simplifies algorithm, any constant < 1/2 also works. 4/27/2019 AOO/Demeter

Recall: Class graph minimization Fruit : Apple | Orange *common* Weight. Apple=. Orange=. 1 + 0.5 = 1.5 (1+2=3) Apple = Weight. Orange = Weight. 2 w w w 4/27/2019 AOO/Demeter

Problem: Redundant part elimination (= abstraction of common parts) may lead to multiple inheritance. R H HeightRelated : Brick | Sphere *common* Height. RadiusRelated : Coin | Sphere *common* Radius. C B S 4/27/2019 AOO/Demeter

Class graph minimization Problem: NP-hard input: class graph G output: class graph H of minimum alternation- edge size and object-equivalent to G Problem: Polynomial input: class graph G with tree property output: class graph H with minimum number of alternation edges and object-equivalent to G. construction edges G = construction edges H. 4/27/2019 AOO/Demeter

Algorithm Construct collection of concrete class subsets Subset containment relationships determine inheritance structure Minimum graph will be single inheritance 4/27/2019 AOO/Demeter

Algorithm Containment relationships between subclass sets determine single inheritance structure. x1 A B C D x2 x3 x2 x3 E F x1 A B C E F D 4/27/2019 AOO/Demeter

Summary: class graph min. Simple algorithms for minimizing construction edges finding object-equivalent single inheritance class graph minimizing alternation edges provided tree-property holds Those algorithms can be easily applied manually during OOD. 4/27/2019 AOO/Demeter

Summary: class graph min. Problem to watch out for: minimizing construction edges may introduce multiple inheritance Multiple inheritance can always be eliminated by introducing additional classes 4/27/2019 AOO/Demeter