CS 189 today

fallsnowpeasInternet και Εφαρμογές Web

12 Νοε 2013 (πριν από 3 χρόνια και 6 μήνες)

70 εμφανίσεις

CS 189 today

Open
-
ended project option…

A few more problems…

… and one more algorithm!

Jotto game finale?!

Rest of the term

No meeting
on Tuesday, November 4
th

Riverside contest on Saturday, November 9
th


Final meeting
of CS 189 on Tuesday, Nov. 12
th


-

quick review of the contest

-

project proposals due (optional…)

-

remember
: problems can be submitted to term's end: 12/23

Jotto!

JRs

SRs

other

diner 1

This term's first class to guess another's word earns 1 problem...

diner 1

diner 2

This term's last class to have its word guessed earns 1 problem...

Sophs

diner 1

POM
-
CMC
-
SCR
-
PTZ

diner 1

about 3

about 0

about 1

about 1

about 1

yearn 2

yearn 0

yearn 1

yearn 2

yearn 2

jotto 2

jotto 0

jotto 1

jotto 0

jotto 1

syrup 1

syrup 1

syrup 1

syrup 2

syrup 1

Projects?


Alums:

What do you feel you
didn't get
@ HMC CS?

Paul Scott

Josh Klontz

Josh Ehrlich

Moira Tagle

Karen Gragg

Will Scott

Answers…


Alums:

What do you feel you
didn't get
@ HMC CS?

Paul Scott

Josh Klontz

Josh Ehrlich

Moira Tagle

Will Scott

Karen Gragg

Optional open
-
ended project



worth up to +12 problems ~ also, an opportunity…



… to try out / get familiar with / learn about a


technology
,
domain
,
library
, or
project

that might be one of your answers to the question,
What do you feel you didn't learn @ HMC?

Optional open
-
ended project

that might be one of your answers to the question,
What do you feel you didn't learn @ HMC?

(0) decide what you'd like to learn…

(1) find a reasonable resource for it…

(2) create a project and a write
-
up…

(3) time expectation: 3 hours per week

Plan:



worth up to +12 problems ~ also, an opportunity…



… to try out / get familiar with / learn about a


technology
,
domain
,
library
, or
project

Optional open
-
ended project

that might be one of your answers to the question,
What do you feel you didn't learn @ HMC?

OpenCV

Qt

other UI library

game dev. library

console

library?

hardware project
requiring programming

something you've
wanted to do but
you wouldn't
otherwise get to

web basics:
HTML/CSS/Jav
ascript/JQuery

"Minecraft"
technology?

framework,
e.g., web
framework
(
Django

et al.)

en.wikipedia.org/wiki/
Comparison_of_web_

application_frameworks



worth up to +12 problems ~ also, an opportunity…



… to try out / get familiar with / learn about a


technology
,
domain
,
library
, or
project

Drawbacks?



specific technologies should be
avoided in the CS curriculum

I agree. Yet this one
-
unit
course is too small to shift
that balance...



there's not enough support to
make it work

True! I'm no expert at what
you're working on, but here
the goal's not expertise, but
the "working on" …



too much time is required…!

3 good
-
faith hours per week +
write
-
up == 12 problems

Drawbacks?

Benefits?



it never hurts to have an
on
-
line portfolio of one or
more of your projects...



helps the limitations of
DWIC

letters, because it's
unique + personalized



curricular support vs.
expertise support



sometimes the benefits
don't
outweigh
the drawbacks

one unit!

John Grasel, Cris Cecka

"did well in class"



specific technologies should be
avoided in the CS curriculum

I agree. Yet this one
-
unit
course is too small to shift
that balance...



there's not enough support to
make it work

True! I'm no expert at what
you're working on, but here
the goal's not expertise, but
the "working on" …



too much time is required…!

3 good
-
faith hours per week +
write
-
up == 12 problems

Interested? To do by 11/12:

project proposal due

2
-
3 paragraphs:

(0) Use the CS wiki or some similar site…

(1) Describe your overall project idea(s)

(2) Describe your plan/resources



online tutorial or course?



do you have a "Hello, World!" version?

(3) Document your time
-
spent

(4) Check
-
in with me on 11/12 (or before…)

grading ~
worth up to 12 problems…

PHP's

WAT!

php >
$x = "209";

php >
$x++;

php >
print( $x ); print( "
\
n" );

210

php

a

PHP's

WAT!

php >
$x = "209";

php >
$x++;

php >
print( $x ); print( "
\
n" );

210


php >
$x = "may";

php >
$x++;

php >
print( $x ); print ( "
\
n" );

maz

php >
$x++;

php >
print( $x ); print ( "
\
n" );

mba

php


a

$x = "2d9";

Now, let's try it with…

Ford
-
Fulkerson algorithm

What's the maximum flow possible,
from src to sink?

s

B

E

D

C

13

t

16

10

4

9

12

14

7

20

4

source

capacity

Max Flow !

sink or target

s

B

E

D

C

13

s

B

C

D

E

FROM

s

B

C

D

E

t

-

16

13

-

-

-

-

10

12

-

-

4

-

-

14

-

-

9

-

-

-

-

-

7

-

-

-

-

20

4

-

-

-

-

-

-

t

t

16

10

4

9

12

14

7

20

4

TO

Capacity Graph

source

sink

(Step #1)

Use depth
-

or breadth
-
first
search to find
any
path from s to t.

Max Flow

What's left ?

s

B

E

D

C

13

s

B

C

D

E

s

B

C

D

E

t

-

16

13

-

-

-

-

10

12

-

-

4

-

-

14

-

-

9

-

-

-

-

-

7

-

-

-

-

20

4

-

-

-

-

-

-

t

t

4
/16

10

4

9

0
/12

14

7

8
/20

4

source

sink

(Step #2)

Compute RESIDUAL graph

Max Flow

What's left…

s

B

C

D

E

s

B

C

D

E

-

4

13

-

-

12

-

10

0

-

-

4

-

-

14

-

12

9

-

-

-

-

-

7

-

-

-

-

8

4

-

-

-

12

-

-

t

t

Residual capacities.

and the
red

edges?

Backwards capacities!

12

12

12

s

B

E

D

C

13

s

B

C

D

E

s

B

C

D

E

t

-

16

13

-

-

-

-

10

12

-

-

4

-

-

14

-

-

9

-

-

-

-

-

7

-

-

-

-

20

4

-

-

-

-

-

-

t

t

4

10

4

9

0

14

7

8

4

source

sink

(Step #3)

Repeat until no path exists…

Max Flow

s

B

C

D

E

s

B

C

D

E

-

4

13

-

-

12

-

10

0

-

-

4

-

-

14

-

12

9

-

-

-

-

-

7

-

-

-

-

8

4

-

-

-

12

-

-

t

t

12

12

12

Residual capacities.

Backwards capacities.

B

E

D

C

12
/13

11
/16

0
/10

1
/4

0
/9

12
/12

11
/14

7
/7

19
/20

4
/4

max flow:

23

Max Flow

s

source

t

sink

(Step #3)

Repeat until no path exists…

(Step #2)

Compute RESIDUAL graph

(Step #1)

Use depth
-

or breadth
-
first search to find
any
path from s to t.

Python…

if

__name__ ==
"__main__"
:



# make a capacity graph


# node A B C D E F


C = [ [ 00, 16, 13, 00, 00, 00 ],
# A


[ 00, 00, 10, 12, 00, 00 ],
# B


[ 00, 04, 00, 00, 14, 00 ],
# C


[ 00, 00, 9, 00, 00, 20 ],
# D


[ 00, 00, 00, 7, 00, 4 ],
# E


[ 00, 00, 00, 00, 00, 00 ] ]
# F



print

"C is"
, C


source = 0
# A


sink = 5
# F



max_flow_value =
max_flow
( C, source, sink )


print

"max_flow_value is"
, max_flow_value

Linked at the ACM website by the slides…

def

max_flow
(C, source, sink):


n = len(C)
# C is the capacity matrix


F = [[0] * n for i in range(n)]
# F is the flow matrix


# residual capacity from u to v is C[u][v]
-

F[u][v]



while

True
:


path =
BFS(C, F, source, sink)


if not

path:
break
# no path
-

we're done!



# find the path's flow, that is, the "bottleneck"


edges = [C[u][v]
-
F[u][v]
for

u,v
in

path]


path_flow =
min
( edges )




print

"Augmenting by"
, path_flow


for

u,v
in

path:
# traverse path to update flow


F[u][v] += path_flow
# forward edge up


F[v][u]
-
= path_flow
# backward edge down



return

sum([F[source][i]
for

i
in

range
(n)])
# out from source

edmonds_karp algorithm

Python…

def

BFS
(C, F, source, sink):


queue = [source]
# the BFS queue



paths = {source: []}
# stores 1 path per graph node


while

queue:



u = queue.pop(0)
# next node to explore (expand)


for

v
in

range
(
len
(C)):
# for each possible next node





# path from u to v? and not yet at v?


if

C[u][v]
-

F[u][v] > 0
and

v
not

in

paths:


paths[v] = paths[u] + [(u,v)]


if

v == sink:


return

paths[v]



queue.append(v)
# go from v in the future


return

None

Python…

Is
maxflow

good
for anything
else
?

that is, beyond solving
maximum
-
flow problems...

we have four brides

and six grooms

and
some
acceptable
possibilities ...

a
bipartite
graph

Matching!

we have four brides

and six grooms

and
some
acceptable
possibilities ...

a
maximal

matching

== no more matchings without rearrangement

Matching!

we have four brides

and six grooms

Matching!

and
some
acceptable
possibilities ...

a
maximum

matching

== no rearrangements will yield more matchings

Maximum matching
is

max flow...

s

source

connect a source to
the left side...

all 1s

Maximum matching
is

max flow...

s

source

connect a source to
the left side...

make all
capacities = 1

1

1

1

1

1

1

all 1s

Maximum matching
is

max flow...

s

source

t

sink

connect a source to
the left side...

put a sink
on the right

make all
capacities = 1

1

1

1

1

1

1

all 1s

all 1s

what do the source and sink constraints ensure?

Max flow thought experiment...

s

source

t

sink

1

1

1

1

1

1

all 1s

all 1s

Suppose this is the flow so far (3 units):

Draw

what happens in the next step of the max
-
flow algorithm!

how to get from
maximal

matching to
maximum

matching…

Max flow thought experiment...

s

source

t

sink

1

1

1

1

1

1

all 1s

all 1s

... the path it finds ...

What's going on here?

Max flow thought experiment...

s

source

t

sink

1

1

1

1

1

1

all 1s

all 1s

Done!

Maximum

matching == 4

This week's problems…

dinner

dining

hardware

muddy

feeding

all can be done
with maxflow…

The challenge:

is often
setting up
the graph

Tools

4 4

42

189

10

1000

50

1 3

20

1 3


8
2


3
1 4

Tasks

How do we use the results?

What

is flowing?

There are four
tools

available ~
at these
costs

hammer

phone

coffee

laptop

There are four
tasks

available ~
with these
rewards

hammer

phone

coffee

PC

4 tools & 4 tasks

each
task

requires
some
tools

E4

PHP
coding

sleep

coding

hardware

Tools

4 4

42

189

10

1000

50

1 3

20

1 3


8
2


3
1 4

source

Tasks

sink

42

189

10

1000

costs

rewards

50

20

8

3

How do we use the results?

What

is flowing?

There are four
tools

available ~
at these costs

hammer

phone

coffee

laptop

There are four
tasks

available ~
with these rewards

4 tools & 4 tasks

each
task

requires
some
tools

hammer

phone

coffee

PC

E4

PHP
coding

sleep

coding

hardware

Tools

4 4

42

189

10

1000

50

1 3

20

1 3


8
2


3
1 4

source

Tasks

sink

42

189

10

1000

costs

rewards

50

20

8

3

How do we use the results?

What

is flowing?

hardware

There are four
tools

available ~
at these costs

hammer

phone

coffee

laptop

There are four
tasks

available ~
with these rewards

4 tools & 4 tasks

each
task

requires
some
tools

hammer

phone

coffee

PC

E4

PHP
coding

sleep

Netflix













4 5

4 5 3 5

3 5 2 6 4

4 5

4 5 3 5

3 5 2 6 3

0 0

number of teams

Input

Output

number of tables

# of people in
each team

can an assignment be
made without putting
teammates together?

1

0

capacity of
each table

again…

end…

3

5

2

6

4

tables with capacities

teams with sizes

5

3

4

5

seating assignments!

no teammates

dinner

s

source

t

sink

How does maxflow help?

Team

Team

Team

Team

Table

Table

Table

Table

Table

4

3

6

5

2

5

5

3

4

fully
connected
with edge
weights of 1

How do these edge weights reflect the problem constraints?

dinner

JRs

SRs

other

diner 1

diner 1

diner 2

Sophs

diner 1

POM
-
CMC
-
SCR
-
PTZ

diner 1

about 3

about 0

about 1

about 1

about 1

yearn 2

yearn 0

yearn 1

yearn 2

yearn 2

jotto 2

jotto 0

jotto 1

jotto 0

jotto 1

syrup 1

syrup
2

syrup 1

syrup 2

syrup 1

chimp 0

chimp 3

chimp 1

chimp 1

chimp 2

today 3

today 0

today 2

today 1

today 2

flags 1

flags 1

flags 0

flags 3

flags 0

ships 0

ships 4

ships 1

ships 2

ships 1

phish 0

phish 5

phish 1

phish 2

phish 1

This term's first class to guess another's word earns 1 problem...

This term's last class to have its word guessed earns 1 problem...

gapes 1

-----

gapes 0

gapes 4

gapes 1

aorta 5

-----

aorta 2

aorta 1

aorta 1

----

-----

sepal 0

sepal 5

sepal 1

Jotto!

JRs

SRs

other

diner 1

This term's first class to guess another's word earns 1 problem...

diner 1

diner 2

This term's last class to have its word guessed earns 1 problem...

Sophs

diner 1

POM
-
CMC
-
SCR
-
PTZ

diner 1

about 3

about 0

about 1

about 1

about 1

yearn 2

yearn 0

yearn 1

yearn 2

yearn 2

jotto 2

jotto 0

jotto 1

jotto 0

jotto 1

syrup 1

syrup 1

syrup 1

syrup 2

syrup 1

This code
only
looks

obfuscated!

No ideas?
Default projects
...

goal:
to get familiar with a variety of web technologies

Project #1
: build a web jotto
-
player and advisor

demo 1
: use HTML, CSS, and CGI forms with Python to choose a
random hidden word and score guesses against that hidden word

demo 2
: use an SQL database to help analyze the comparative
effectiveness of guessing a particular word next, without scoring them all

final demo
: use javascript and AJAX (and/or HTML 5 canvas) features
to make the interface more slick, as befits the noble game of Jotto!

See https://www.cs.hmc.edu/twiki/bin/view/CS5/WebCS5DevelopmentPage

for some (rough) guidance and sample applications on HMC's webserver...

No ideas?
Default projects
...

goal:
to get familiar with a variety of web technologies

Project #1
: build a web
jotto
-
player and advisor

demo 1
: use HTML, CSS, and CGI forms with Python to choose a
random hidden word and score guesses against that hidden word

demo 2
: use an SQL database to help analyze the comparative
effectiveness of guessing a particular word next, without scoring them all

final demo
: use
javascript

and AJAX (and/or HTML 5 canvas) features
to make the interface more slick, as befits the noble game of
Jotto
!

Project #2
: build a web
-
based Python autograder

alternative final demo
: allow a user to submit a program and get
"immediate" feedback as to whether it passed a series of tests or not
(time out as necessary to avoid uncomputability...)

impossible final demo
: show off your
Hyper
-
Turing

quantum computer,
since, after all, the autograder problem is uncomputable

http://www.amirrorclear.net/academic/papers/many
-
forms.pdf

http://www.cs.virginia.edu/~robins/The_Limits_of_Quantum_Computers.pdf

HyperTuring computation is easy


just add coffee to your TM!

Hyper
-
Turing?

Quantum computers are not considered
likely to extend what's computable


only
how efficiently computations can be done.

Hyper
-
turing computation?

HyperTuring computation is easy


just add coffee to your TM!

Hyper
-
turing computation?

HyperTuring computation is easy


just add coffee to your TM!

Survey

JRs

SRs

Elderly

a word
-
guessing game similar to mastermind…

diner ?

This term's first class to guess another's word earns 1 point...

diner ?

diner ?

This term's last class to have its word guessed earns 1 point...

Sophs

diner ?

Pomona?

diner ?

Other points may be possible...

Get together with same
-
year classmates...

(1) Choose a jotto word with/for your class

... and jotto, part 1

(2) Have you built software on your own with technologies
not typically part of Mudd's curriculum? If not, no problem!
If so, great!
-

please mention a detail or two:

(3) Do you already have a plan (or an idea) for a CS189 project
you might want to pursue? If so, what are you considering?

(0) Name: ____________________________

Scores...

JRs

SRs

Others

diner 3

This term's first class to guess another's word earns 1 point...

diner 1

diner 3

This term's last class to have its word guessed earns 1 point...

Sophs

diner 0

Other points may be possible...

Ideas!

... and jotto:

squid 2

squid 1

squid 1

squid 0

neigh 3

neigh 0

neigh 2

neigh 1

No idea:
8

Web App:
12

iPad/iOS:
3

OpenCV:
5

baseball:
1

Android:
2

Audio analysis:
3

576

2319

576

1128

211

1076

279

323

36

213

142

103