23
Program Design Tutorial #3

Program Design Tutorial #3

  • Upload
    preston

  • View
    26

  • Download
    0

Embed Size (px)

DESCRIPTION

Program Design Tutorial #3. The Two Generals Problem. Two armies are camped on the outskirts of either side of an enemy city. The Two Generals Problem. Army 1. Army 2. The Two Generals Problem. - PowerPoint PPT Presentation

Citation preview

Page 1: Program Design Tutorial #3

Program Design

Tutorial #3

Page 2: Program Design Tutorial #3

The Two Generals Problem Two armies are camped on the outskirts of

either side of an enemy city.

Page 3: Program Design Tutorial #3

The Two Generals Problem

Army 1 Army 2

Page 4: Program Design Tutorial #3

The Two Generals Problem The generals of the armies can only

communicate via messengers who must travel through enemy territory and are thus subject to delays or capture.

Page 5: Program Design Tutorial #3

The Two Generals Problem

Message

Page 6: Program Design Tutorial #3

The Two Generals Problem

Acknowledgement

Message

Page 7: Program Design Tutorial #3

The Two Generals Problem The two generals have previously agreed on

a plan of attack, but they must communicate to set up the attack time.

If one army attacks but the other doesn’t they will be defeated and then the enemy city will defeat the other army.

Page 8: Program Design Tutorial #3

The Two Generals Problem If the first general decides to send the

message saying,

◦“Let’s attack at noon tomorrow”

Page 9: Program Design Tutorial #3

The Two Generals Problem One of three things could happen◦Scenario 1◦Scenario 2◦Scenario 3

Page 10: Program Design Tutorial #3

The Two Generals Problem SCENARIO 1

The message could intercepted when it is being sent to the second general

Page 11: Program Design Tutorial #3

The Two Generals Problem

Message

Page 12: Program Design Tutorial #3

The Two Generals Problem

Message

Page 13: Program Design Tutorial #3

The Two Generals Problem

Message

Page 14: Program Design Tutorial #3

The Two Generals Problem SCENARIO 1

So what?

Well Army1 will attack at noon, but Army2 won’t.

Army1 will be defeated.

Army2 will be attacked and defeated.

Page 15: Program Design Tutorial #3

The Two Generals Problem SCENARIO 2 The message could be received by the second

general but the acknowledgement that is sent back could be intercepted.

Page 16: Program Design Tutorial #3

The Two Generals Problem

Acknowledgement

Message

Page 17: Program Design Tutorial #3

The Two Generals Problem

Acknowledgement

Message

Page 18: Program Design Tutorial #3

The Two Generals Problem

Acknowledgement

Message

Page 19: Program Design Tutorial #3

The Two Generals Problem SCENARIO 2 So what?

Well Army2 will attack at noon, but Army1 won’t know if the message was received so Army1 won’t attack in case Army2 doesn’t.

Army2 will be defeated.

Army1 will be attacked and defeated.

Page 20: Program Design Tutorial #3

The Two Generals Problem SCENARIO 3 The message is received by the second general and

the acknowledgement is sent back.

Page 21: Program Design Tutorial #3

The Two Generals Problem

Acknowledgement

Message

Page 22: Program Design Tutorial #3

The Two Generals Problem SCENARIO 3 So what?

Army1 and Army2 attacked together, and defeat the enemy.

Page 23: Program Design Tutorial #3

The Two Generals Problem In groups of three or four, think of five ways to

help ensure that both armies attack together.