Lecture 14: Other Kinds of Constraints

Slides:



Advertisements
Similar presentations
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Advertisements

1 Lecture 8: Constraints Brad Myers Advanced User Interface Software.
Chapter 1 Program Design
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
GUI Design Spreadsheet-Based Decision Support Systems Chapter 23: Aslı Sencer MIS 463.
Rev.S08 MAC 1140 Module 9 System of Equations and Inequalities I.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
Lecture 11: Constraints Brad Myers Advanced User Interface Software 1© Brad Myers.
1 Lecture 5: Interactive Tools: Prototypers (HyperCard, Director, Visual Basic), Interface Builders Brad Myers Advanced User Interface Software.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
Lecture 10: Constraints Brad Myers Advanced User Interface Software 1.
Comments, Conditional Statements Continued, and Loops Engineering 1D04, Teaching Session 4.
Controlling Program Flow with Decision Structures.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
VISUAL BASIC 6.0 Designed by Mrinal Kanti Nath.
Visual Basic.NET Windows Programming
Processes and threads.
Distributed Shared Memory
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2017.
CSC 421: Algorithm Design & Analysis
CSC 421: Algorithm Design & Analysis
William Stallings Computer Organization and Architecture 8th Edition
GC211Data Structure Lecture2 Sara Alhajjam.
ALGORITHMS AND FLOWCHARTS
CSC 421: Algorithm Design & Analysis
CS1371 Introduction to Computing for Engineers
Optimization Code Optimization ©SoftMoore Consulting.
Introduction to Operating System (OS)
Introduction To Flowcharting
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Winter 2013.
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Algorithm Analysis CSE 2011 Winter September 2018.
Programming Fundamentals
TIM 58 Chapter 8: Class and Method Design
Chap 7. Building Java Graphical User Interfaces
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Zach Tatlock Winter 2018.
Graphical User Interfaces -- Introduction
Chapter 2 Visual Basic Interface
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
ALGORITHMS AND FLOWCHARTS
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2013.
Topic 8: (Last two papers)
How to develop a program?
Chapter 8: Advanced Pattern Matching
Objective of This Course
Functional Programming
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2016.
Programming in JavaScript
ALGORITHMS AND FLOWCHARTS
JavaScript.
More programming with "Processing"
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Autumn 2018.
Lecture 2- Query Processing (continued)
Multithreaded Programming
Programming in JavaScript
MANAGING THE DEVELOPMENT AND PURCHASE OF INFORMATION SYSTEMS
CSC 421: Algorithm Design & Analysis
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
Basic Concepts of Algorithm
Working with Formulas and Functions
CSC 421: Algorithm Design & Analysis
Brad Myers : Interaction Techniques Spring, 2019
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2019.
Presentation transcript:

Lecture 14: Other Kinds of Constraints Brad Myers 05-830 Advanced User Interface Software Spring, 2017 © 2017 - Brad Myers

Constraints Relationships defined once and maintained by the system Useful for keeping parts of the graphics together. Typically expressed as arithmetic or code relationships among variables. Variables are often the properties of objects (left, color) Types: "Dataflow" constraints;  Choices: Single-Output vs. Multi-output Types: One-way, Multi-way, Simultaneous equations, Incremental, Special purpose Cycles: supported or not Others: AI systems, scheduling systems, etc. © 2017 - Brad Myers

Historical Note: “Active Values” Old Lisp systems had active values Attach procedures to be called when changed Similar to today’s “Listeners” Like the “reverse” of constraints Procedures are attached to values which change instead of values where needed Inefficient because all downstream values are re-evaluated, possibly many times E.g., when x and y values change © 2017 - Brad Myers

One Way Constraints Simplest form of constraints D = F(I1, I2, ... In) Often called formulas since like spreadsheets Can be other dependencies on D CurrentSliderVal = mouseX - scrollbar.left scrollbar.left = window.left + 200 scrollbar.visible = window.has_focus © 2017 - Brad Myers

One Way Constraints, cont. Not just for numbers: mycolor = x.color Implementations: 1. Just re-evaluate all required equations every time a value is requested least storage, least overhead Equations may be re-evaluated many times when not changed. (e.g, scrollbar.left when mouse moves) cycles: file_position = F1(scrollbar.Val) scrollbar.Val = F2(file_position) Objects may jitter – change X and then change Y Cannot detect when values change (to optimize redraw) © 2017 - Brad Myers

One-Way Implementation 2 (Review of Scott Hudson’s algorithm) Cache current values with each constraint; lazy eval Example: A = 10 B = A + 5 C = A * B D = A + E E = 20 F = D + C now need to know when values become invalid and recalculate in right order © 2017 - Brad Myers

Implementation 2, cont. Two phases: invalidate and re-calculate invalidate all values that depend on the changed value recalculate only values that are demanded data structures: depends-on-me, i-depend-on may re-evaluate values that haven't changed unnecessarily when conditionals, "max", etc. can mark slots/objects that change can detect cycles with a counter © 2017 - Brad Myers

Garnet / Amulet Constraint Solving Default: one-way, data flow constraints with variables in the dependencies, support for cycles, and multiple changes before solving Efficient enough for ubiquitous use Garnet text button widget contains 43 constraints internally, and the Lapidary graphical interface builder contains 16,700 constraints Also can bring in alternative solvers Brad Vander Zanden’s multi-way solver [Vander Zanden 1996] “Animation Constraints” [Myers 1996] Snippets of video for Garnet and Amulet constraints © 2017 - Brad Myers

Garnet / Amulet Default Algorithm Variables in the dependencies Example: D = p^.left + A Important innovation in Garnet we invented, now ubiquitous Supports feedback objects outlineRect.left = selectedObject^.left … circle1.object_over = rect34 circle1.left = self.object_over.right + 10 Supports loops: D = Max(components^) Only evaluates needed part of conditionals width = if otherpart.value > tolerance then expensive computation else otherpart.width Requires the dependencies be dynamically determined © 2017 - Brad Myers

Key addition to Hudson’s algorithm Allow for dependency graph to change while evaluating the constraints Keep a “timestamp” on each dependency to detect when it is no longer needed Example circle1.object_over = rect34 circle1.left = self.object_over.right + 10 …(later) circle1.object_over = circle12 Now don’t want circle1 to be recalculated when rect34 changes See details in [Vander Zanden 94] required reading Especially section 4 © 2017 - Brad Myers

Examples of Expressing Constraints Garnet: (create-instance NIL opal:line (:points '(340 318 365 358)) (:grow-p T) (:x1 (o-formula (first (gvl :points)))) (:y1 (o-formula (second (gvl :points)))) (:x2 (o-formula (third (gvl :points)))) (:y2 (o-formula (fourth (gvl :points))))) Amulet: Am_Define_Formula (int, height_of_layout) { int h = (int)Am_Height_Of_Parts(self) + 2 * ((int)self.Get(Am_TOP_OFFSET)); return h < 75 ? 75 : h; } am_empty_dialog = Am_Window.Create("empty_dialog_window") .Set (Am_LEFT_OFFSET, 5) // used in width_of_layout .Set (Am_TOP_OFFSET, 5) // used in height_of_layout .Set (Am_WIDTH, width_of_layout) .Set (Am_HEIGHT, height_of_layout) ... © 2017 - Brad Myers

Other One-Way Variations Multiple outputs (D1, D2, ... Dm) = F(I1, I2, ... In) Side-effects in the formulas useful for creating objects when happen? what if create new objects with new constraints cycles cannot be detected Constant formula elimination To decrease the size used by constraints © 2017 - Brad Myers

Two-Way (Multi-way) Constraints From ThingLab (~1979) Constraints are expressions with multiple variables Any may be modified to get the right values Example: A.right = A.left + A.width - 1 Often requires programmer to provide methods for solving the constraint in each direction: A.left = A.right - A.width + 1 A.width = A.right - A.left + 1 Useful if mouse expressed as a constraint © 2017 - Brad Myers

Two-Way implementations Requires a planning step to decide which way to solve Many systems compute plans and save them around since usually change same variable repeatedly In general, have a graph of dependencies, find a path through the graph How control which direction is solved? CurrentSliderVal = mouseX - scrollbar.left "Constraint hierarchies" = priorities constants, interaction use "stay" constraints with high priority Dynamically add and remove constraints Brad Vander Zanden's "QuickPlan" solver Handles multi-output, multi-way cyclic constraints in O(n2) time instead of exponential like previous algorithms © 2017 - Brad Myers

Simultaneous Equations Required for parallel, perpendicular lines; tangency, etc. Also for aggregate's size Numerical (relaxation) or symbolic techniques © 2017 - Brad Myers

Incremental Michael Gleicher's PhD thesis, 1994 Only express forward computations Tries to get reverse by incrementally changing the forward computation in the right direction using derivatives. Supports interactions otherwise not possible Produces smooth animations © 2017 - Brad Myers

Animation Constraints in Amulet Implemented using Amulet's constraint mechanism When slot set with a new value, restores old value, and animates from old to new value Usually, linear interpolation For colors, through either HSV or RGB space For visibility, various special effects between TRUE and FALSE Demo © 2017 - Brad Myers

Some Constraint Systems Today Flex “data bindings” Ember. http://emberjs.com/ MVC, “Computed Properties” KnockoutJS. http://knockoutjs.com/ Backbone: http://documentcloud.github.com/backbone/ MVC, “Change” events constraints apparently implemented by others on top Google’s AngularJS Stephen Oney’s ConstraitJS © 2017 - Brad Myers

Hints for HW#4 Important to make it possible to write new constraints Constraints should work on colors as well as numbers Should be able to do arithmetic with numbers, but OK to just pass colors around (rect1.color = rect2.color) Edit the test file to make clear how your constraints should be written Add the constraint solving passes to your overall event handling and refresh loop from hw#3 © 2017 - Brad Myers