ORF 201 Computer Methods in Problem Solving. Final Project: Dynamic Programming Optimal Sailing Strategies

Similar documents
Iteration: while, for, do while, Reading Input with Sentinels and User-defined Functions

Excel Solver Case: Beach Town Lifeguard Scheduling

UNIVERSITY OF WATERLOO

Calculation of Trail Usage from Counter Data

Lab 4: Root Locus Based Control Design

PHYS Tutorial 7: Random Walks & Monte Carlo Integration

Optimal Weather Routing Using Ensemble Weather Forecasts

The Incremental Evolution of Gaits for Hexapod Robots

The system design must obey these constraints. The system is to have the minimum cost (capital plus operating) while meeting the constraints.

i) Linear programming

ECO 199 GAMES OF STRATEGY Spring Term 2004 Precept Materials for Week 3 February 16, 17

COMPASS DIRECTION AND BEARINGS

CHILDREN S CUP May 12, 2018 FAIRHOPE YACHT CLUB PHRF/Portsmouth SAILING INSTRUCTIONS

CS Problem Solving and Object-Oriented Programming Lab 2 - Methods, Variables and Functions in Alice Due: September 23/24

Traffic circles. February 9, 2009

Supporting Online Material for Evolution of Contingent Altruism when Cooperation is Expensive June, 2005

Queue analysis for the toll station of the Öresund fixed link. Pontus Matstoms *

CS 351 Design of Large Programs Zombie House

You are to develop a program that takes as input the scorecard filled out by Bob and that produces as output the correct scorecard.

Assignment A7 BREAKOUT CS1110 Fall 2011 Due Sat 3 December 1

ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering. Mini-project 3 Tennis ball launcher

3D Inversion in GM-SYS 3D Modelling

Technical Brief - Wave Uprush Analysis Island Harbour Club, Gananoque, Ontario

HIGH RESOLUTION DEPTH IMAGE RECOVERY ALGORITHM USING GRAYSCALE IMAGE.

play the right side of the course that significantly reduces your options and flexibility.

Naval Postgraduate School, Operational Oceanography and Meteorology. Since inputs from UDAS are continuously used in projects at the Naval

SE Learning Task: Hot Air Balloons: MCC7.NS.1 I. Make a balloon model and vertical number line.

INSTITUTE AND FACULTY OF ACTUARIES. Curriculum 2019 AUDIT TRAIL

Boyle s Law: Pressure-Volume Relationship in Gases

Assignment #3 Breakout! Due: 12pm on Wednesday, February 6th This assignment should be done individually (not in pairs)

INTRODUCTION Page 2 SETTINGS

Assignment #3 Breakout!

The ICC Duckworth-Lewis-Stern calculator. DLS Edition 2016

HOW TO BECOME A FAST GUY II (Upwind Racing Tactics) By Bob Szczepanski

Cover Page for Lab Report Group Portion. Pump Performance

Mitos Fluika Pressure and Vacuum Pumps Datasheet

EDEXCEL NATIONALS UNIT 6 MECHANICAL PRINCIPLES and APPLICATIONS. ASSIGNMENT No. 4

Mixture Models & EM. Nicholas Ruozzi University of Texas at Dallas. based on the slides of Vibhav Gogate

March Madness Basketball Tournament

Using Markov Chains to Analyze a Volleyball Rally

COMPUTATIONAL OCEAN ACOUSTIC TOOLBOX MANUAL. Computational Ocean Acoustics Toolbox (COAT) is a package written containing the following

Grade: 8. Author(s): Hope Phillips

Vectors in the City Learning Task

: A WEB-BASED SOLVER FOR COMPRESSIBLE FLOW CALCULATIONS

Below are the graphing equivalents of the above constraints.

CVEN Computer Applications in Engineering and Construction. Programming Assignment #4 Analysis of Wave Data Using Root-Finding Methods

SoundCast Design Intro

Ammonia Synthesis with Aspen Plus V8.0

BERNOULLI EFFECTS ON PRESSURE.ACTIVATED W ATER LEVEL GAUGES

LOCOMOTION CONTROL CYCLES ADAPTED FOR DISABILITIES IN HEXAPOD ROBOTS

A IMPROVED VOGEL S APPROXIMATIO METHOD FOR THE TRA SPORTATIO PROBLEM. Serdar Korukoğlu 1 and Serkan Ballı 2.

Friday 30 th November to Sunday 2 nd December Organising Authority: Derwent Sailing Squadron Inc. 1 P a g e

PART 5 - OPTIONS CONTENTS 5.1 SYSTEM EXPANSION 5-3

NUMB3RS Activity: Walkabout. Episode: Mind Games

ORC Software Module for Performance Curve Calculation (PCS) Specifications

Using the Lego NXT with Labview.

Ocean Fishing Fleet Scheduling Path Optimization Model Research. Based On Improved Ant Colony Algorithm

Assignment 3: Breakout!

March Madness Basketball Tournament

Pegas 4000 MF Gas Mixer InstructionManual Columbus Instruments

Ten Problems About Twenty- Five Horses

Civil Engineering Computation. Numerical Methods : Root Finding and Optimization

EVOLVING HEXAPOD GAITS USING A CYCLIC GENETIC ALGORITHM

A statistical model of Boy Scout disc golf skills by Steve West December 17, 2006

Workshop 1: Bubbly Flow in a Rectangular Bubble Column. Multiphase Flow Modeling In ANSYS CFX Release ANSYS, Inc. WS1-1 Release 14.

TOPIC 10: BASIC PROBABILITY AND THE HOT HAND

Why We Should Use the Bullpen Differently

Introduction to Pattern Recognition

Problem Solving as Search - I

1 RULES 1.1 The regatta will be governed by the rules as defined in The Racing Rules of Sailing (RRS)

E. Agu, M. Kasperski Ruhr-University Bochum Department of Civil and Environmental Engineering Sciences

by Robert Gifford and Jorge Aranda University of Victoria, British Columbia, Canada

The Game of Yinsh (Phase II)

Lesson Author: Adapted from Tom Lochhaas How to Tack a Sailboat:

Online Companion to Using Simulation to Help Manage the Pace of Play in Golf

2008 Excellence in Mathematics Contest Team Project B. School Name: Group Members:

EE 364B: Wind Farm Layout Optimization via Sequential Convex Programming

CHAPTER 6 DISCUSSION ON WAVE PREDICTION METHODS

Navigate to the golf data folder and make it your working directory. Load the data by typing

Gas exchange measurement in module M- COVX

Project 1 Those amazing Red Sox!

Race Screen: Figure 2: Race Screen. Figure 3: Race Screen with Top Bulb Lock

CSE 154: Web Programming Spring 2017 Homework Assignment 5: Pokedex. Overview. Due Date: Tuesday, May 9th

1 PIPESYS Application

Ranking teams in partially-disjoint tournaments

Performance Task # 1

Lab 2: Probability. Hot Hands. Template for lab report. Saving your code

MoLE Gas Laws Activities

Title: Modeling Crossing Behavior of Drivers and Pedestrians at Uncontrolled Intersections and Mid-block Crossings

How to set up and use DeWiggler Analyst

GLMM standardisation of the commercial abalone CPUE for Zones A-D over the period

Lab 1. Adiabatic and reversible compression of a gas

SAILING INSTRUCTIONS

Manual For Race Directors Space Coast Model Sailing Club

INSTRUCTION FOR FILLING OUT THE JUDGES SPREADSHEET

One of the most-celebrated feats

Lesson Author: Adapted from Tom Lochhaas How to Tack a Sailboat:

Controlling the prefeeder

Fall 2008 RED Barcode Here Physics 105, sections 1 and 2 Please write your CID Colton

Characterizers for control loops

Transcription:

Princeton University Department of Operations Research and Financial Engineering ORF 201 Computer Methods in Problem Solving Final Project: Dynamic Programming Optimal Sailing Strategies Due 11:59 pm, May 9, 2000 1. PROBLEM DESCRIPTION In this project, we wish to find the quickest path for a sailboat to go from a starting point A to a destination B accounting explicitly for the random fluctuations of the wind, the fact that a sailboat cannot sail directly into the wind, and that changing heading in such a way that the wind changes from one side of the boat to the other takes time. This project is a final project. It counts for 20 points. It cannot be used as one of the assignments whose grade is dropped. For this project you are expected to work alone. Furthermore, the TAs are instructed not to provide debugging help so you should not seek it. 2. THE MODEL AND ITS ASSUMPTIONS We will model a lake by a rectangular lattice of points (x, y), x, y = 0, 1,..., N. The south shore and the north shore correspond to the bottom and top edges of the lattice: (x, 0) and (x, N), x = 0, 1,..., N. Similarly, the west shore and the east shore correspond to the left and right edges of the lattice: (0, y) and (N, y), y = 0, 1,..., N. All other points of the lattice x, y = 1, 2,..., N 1 will correspond to actual positions on the lake. From a position (x, y) on the lake, we assume that the sailboat can only sail in one of eight directions: north to (x, y + 1), south to (x, y 1), east to (x + 1, y), west to (x 1, y), 1

2 northeast to (x + 1, y + 1), southeast to (x + 1, y 1), northwest to (x 1, y + 1), or southwest to (x 1, y 1). If the sailboat gets beached along one of the four bounding beaches, then it is stuck there forever (losing the race). We also assume that the wind only blows from one of the eight directions listed above. We say that the sailboat is on a starboard tack if the wind is hitting the sailboat on the right side. If the wind is hitting the boat on the left, then the sailboat is said to be on a port tack. (If the boat is heading directly into the wind or directly away from the wind, then it is on neither a starboard nor a port tack.) For example, if the boat is heading northeast, then winds out of the east, southeast, and south correspond to starboard tacks, whereas winds out of the north, northwest, and west correspond to port tacks. We assume that the wind is constant as the sailboat sails from one lattice point to the next, but that once the sailboat gets to a new lattice point the wind can change. The new wind is random, its distribution depending on the old wind according to a table of probabilities such as this:... NEW N NE E SE S SW W NW OLD... N 0.4 0.3 0.3 NE 0.4 0.3 0.3 E 0.4 0.3 0.3 SE 0.4 0.3 0.3 S 0.4 0.2 0.4 SW 0.3 0.3 0.4 W 0.3 0.3 0.4 NW 0.4 0.3 0.3 Blank entries in the table have probability zero. (Note that this is an example of a sparse matrix, but for simplicity we ll store it just as a two-dimensional array.) We assume further that the skipper sees the new wind direction (from the pattern of ripples it makes on the water) before the new wind actually hits the sails. 3. ENCODINGS It will be convenient to encode the sailing headings and the wind directions according to the following scheme:

3 Value Direction 0 N 1 NE 2 E 3 SE 4 S 5 SW 6 W 7 NW If w denotes the wind direction and h denotes the current heading, then the sailboat is on a starboard tack if { w h if w >= h, tack(w, h) = w h + 8 otherwise takes the value 1, 2 or 3 and it is on a port tack if tack(w, h) is 5, 6 or 7. If the value is 0 or 4, then the boat is not on a tack. 4. DYNAMIC PROGRAMMING Time will be discretized so that the skipper only has to make decisions when arriving at a new lattice point. At this time, the skipper knows the current position (x, y), the current tack t (i.e., either port= 0, starboard= 1 or no tack= 2) and the new wind direction w. Based on this information she must decide on a new heading. Let v(x, y, t, w) denote the minimum expected amount of time to reach the destination from this point on. If the skipper (or is it skippess?) decides to head out from the current lattice point along heading h, then, given this decision, the minimum expected time to reach the destination will be where delay(t, t ) + time(w, h) + w {0,1,...,7 P (w, w )v(x + x h, y + y h, t, w ) t is the new tack associated with the new wind w and the new heading h. delay(t, t ) is the delay associated with a change in tack. delay(t, t ) is zero if t and t are the same or if either t or t corresponds to a no-tack situation. Otherwise, delay(t, t ) is a positive number delay (corresponding to a switch from a port tack to a starboard tack or a switch from a starboard tack to a port tack). time(w, h) is the time it takes to reach the next lattice point given that the sailboat is being sailed along heading h and the wind is coming from direction w. The time to travel one unit of distance (such as from (x, y) to (x + 1, y)) will take on one of five values depending on tack(w, h):

4 tack(w, h) Time 0 into wind time 1,7 up wind time 2,6 cross wind time 3,5 down wind time 4 away wind time Values for these five times will be part of the input for the problem. Generally speaking, into the wind time is infinite (since sailboats can t sail into the wind) and each subsequent time down the list is shorter than the one before. time(w, h) will be one of these five times if the heading h is either north, south, east or west. But if the heading h is along one of the diagonal directions, then the time must be multiplied by 2 to account for the somewhat longer distance that must be traveled. P (w, w ) is the probability that the next new wind direction will be w given that the current new wind is w. These probabilities are taken from the table above. x h is the change in the x coordinate given that the heading is h and y h is the change in the y coordinate given that the heading is h. Since the skipper wants to pick the new heading so as to minimize the expected time, we see that v(x, y, t, w) = min h {0,1,...,7 delay(t, t ) + time(w, h) + w {0,1,...,7 P (w, w )v(x + x h, y + y h, t, w ) The function v(x, y, t, w) defined above is found by using an iterative scheme which we now describe. For all possible values of t and w, v(x, y, t, w) is initialized to infinity at all points (x, y) except for the destination point B at which v(x, y, t, w) is set to zero. (Of course, infinity is simply chosen to be a sufficiently large number.) Then, for a given x, y, t and w, v(x, y, t, w) is improved by replacing its current value with the value computed as follows: v(x, y, t, w) = min h {0,1,...,7 delay(t, t ) + time(w, h) + w {0,1,...,7 P (w, w )v(x + x h, y + y h, t, w ) These improved values are computed for all x, y, t and w. The new values of v(x, y, t, w) are still an overestimate of the true function. So this improvement procedure is continued several times until the change from one pass through all choices of x, y, t and w to the next produces only a very small maximum change in any of the estimates. At this point we declare that we have found the function v(x, y, t, w). Given the function v(x, y, t, w), it is easy to see what the optimal strategy should be. Namely, always choose the heading h that attains the minimum in the right-hand side of the above equation. 5. COMPUTER ALGORITHM The above dynamic programming equations suggest the following computer algorithm.

First, we initialize v(x, y, t, w) to infinity everywhere except at the destination B where it is initialized to zero: 5 foreach x in 0,...,N { foreach y in 0,...,N { foreach t in 0,1,2 { foreach w in 0,1,...,7 { v(x, y, t, w) = foreach t in 0,1,2 { foreach w in 0,1,...,7 { v(x B, y B, t, w) = 0 Then we update the initial estimate at every point on the lake except at the destination B, keeping track of the largest change in the estimate in a variable called error and saving the best heading out of each situation x, y, t and w in bestheading(x, y, t, w). These iterations are to continue until error is less than some small tolerance, say 1.0e-3. do { error = 0 foreach x in 1,...,N-1 { foreach y in 1,...,N-1 { if ( (x, y) (x B, y B ) ) { foreach t in 0,1,2 { foreach w in 0,1,...,7 { new value = min h {0,1,...,7 {delay(t, t ) + time(w, h) + w {0,1,...,7 P (w, w )v(x + x h, y + y h, t, w ) if ( new value v(x, y, t, w) > error ) error = new value v(x, y, t, w) bestheading(x, y, t, w) = h attaining the min above v(x, y, t, w) = new value while ( error > smalltolerance )

6 6. DATA STRUCTURES The functions v(,,, ) and bestheading(,,, ) should be represented in the computer as four dimensional arrays. For example, the declaration of v might be something like this: double[][][][] v = new double[n+1][n+1][3][8]; Then, if x and y are integers between 0 and N, t is an integer equal to 0, 1 or 2 and w is an integer between 0 and 7, then v(x, y, t, w) is referred to as v[x][y][t][w] = /* whatever */ 7. GETTING STARTED As usual, you need to create a directory in which to work: Begin like this: cd public_html/java/orf201 mkdir sail cd sail Then you need to copy over the following files: cp /u/orf201/public_html/java/orf201/sail/index.html. cp /u/orf201/public_html/java/orf201/sail/sail.html. cp /u/orf201/public_html/java/orf201/sail/sail.java. Compile the java code that you just copied over: javac Sail.java Then use appletviewer to see what the code currently does: appletviewer sail.html An applet window should pop up with button labelled Push here to go sailing. Pressing that button brings up another window (the sf instance of a SailFrame) that allows you to define and then solve the sailing problem. The SailFrame is divided into a left-hand part and a right-hand part. The left-hand part is an InPanel called ip that contains three buttons and a number of textfields into which the input parameters can be entered. The right-hand side is an instance gp of the class GraphPad. This is where the simulation is to be drawn.

All of the input user-inteface code is included in the file Sail.java. Your job is to code up the algorithm, the simulation, and the graphical output. 7 8. PROGRAMMING NOTES Use less than 8 spaces for indentation (4 would be good) otherwise you ll find your code running off on the right. You will find it convenient to use the absolute-value function. In JAVA, it is accessed via Math.abs(). 9. INPUT The file Sail.java contains all of the code to set up text fields in which you can enter all of the relevant data. 10. OUTPUT The functions v(x, y, t, w) and bestheading(x, y, t, w) represent the answers that you will compute. If these functions had had only two arguments, it would be easy to display the results graphically. However, the fact that there are four arguments makes a graphical representation of them difficult. So, instead, we will simulate the random variations of the wind and display on a two dimensional grid the actual path of the sailboat for the given evolution of wind patterns. We will always assume that the boat is just arriving to point A on a starboard tack and that the wind is about to change, the new wind being out of the northeast. The skipper decides the new heading to exit point A based on bestheading(x A, y A, 1, 1) s recommendation. On reaching the next grid point, the wind is allowed to change randomly according to the given table of probabilities. Using the new wind direction, the skipper again refers to bestheading() to determine the direction to leave this grid point. This procedure is continued until the sailboat reaches its destination B. You should show the path of the sailboat on the grid lake. For each leg of the path, you should indicate whether the boat is on a port or a starboard tack (or neither) by color coding the leg appropriately. You should also show the wind direction for each leg of the trip. After simulating one trip from A to B, you should display (somewhere on the lake) the time the trip took taking into account the time it takes to sail from each grid point along the path to the next grid point and also the delays incurred for each change of tack. In addition, you should display the expected time the trip should take as predicted by the value of v(x A, y A, 1, 1).

8 11. HINTS ON SIMULATION Given an old wind direction, say old w, you will need to generate randomly a new wind direction, say new w, using a two-dimensional array of probabilities, say prob[][]. The following code fragment accomplishes this task: rannum = Math.random(); cumprob = 0.0; for (w=0; w<8; w++) { cumprob += prob[ old_w ][ w ]; if (rannum < cumprob) { break; new_w = w;