ceg 221 lesson 7 algorithm development from start to finish
Download
Skip this Video
Download Presentation
CEG 221 Lesson 7: Algorithm Development From Start to Finish

Loading in 2 Seconds...

play fullscreen
1 / 13

CEG 221 Lesson 7: Algorithm Development From Start to Finish - PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on

CEG 221 Lesson 7: Algorithm Development From Start to Finish. Mr. David Lippa. Overview. Algorithm Development : Stable Marriage What is the Stable Marriage Algorithm? Data Structure Development struct PersonType Function Development Populating people from a file Putting It Together

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CEG 221 Lesson 7: Algorithm Development From Start to Finish' - finn-frazier


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
overview
Overview
  • Algorithm Development : Stable Marriage
    • What is the Stable Marriage Algorithm?
  • Data Structure Development
    • struct PersonType
  • Function Development
    • Populating people from a file
  • Putting It Together
  • Questions
stable marriage algorithm
Stable Marriage Algorithm
  • Assume Equal Numbers of Men & Women
  • One gender proposes, the other accepts/rejects proposals and can dump their current intended.
    • Each follow rules of engagement (ha ha)
  • The overall algorithm:
    • While there are still unengaged people, go through a round of match-making
stable marriage rules of engagement
Men (Proposer)

Unengaged  propose

Dumped  go to next on preference list

Women (Proposee)

Unengaged  accept

Engaged and …

Like current better  tell suitor to buzz off

Like new one better  dump fiancé for the new guy

Stable Marriage:Rules of Engagement
overall algorithm
Overall Algorithm

// define data structures

// make people

// build preference lists

while(someoneIsNotEngaged)

{

for each unengaged man

{

propose to next on preference list

}

}

// display results

define a person
Define a Person

// define NAME_SIZE, NUM_PPL

struct PersonType{ char mName[NAME_SIZE]; struct PersonType* mpSpouse; struct PersonType* mpPreferences[NUM_PPL]; unsigned int mPreferred;

int mHash;};

/* the hash value will be used in populating

each person’s preference list */

load people
Load People
  • We need to get their preference list from the user.
  • In this case, we will be using fprintf / fscanf, and instead of getting input or writing output from/to the terminal, we will be getting it from a file.
  • So let’s define the file
define persons txt
Define Persons.txt
  • Defined to be a list of people
  • Then each person and his/her preference list
  • Do this twice – one for men and for women
make persons txt
Make Persons.txt

5 Austin David Jon Ichabod Manuel

5 Anna Bertha Jamie Katherine Michelle

Austin Michelle Katherine Bertha Anna Jamie

David Katherine Jamie Bertha Anna Michelle

Jon Jamie Anna Michelle Katherine Bertha

Ichabod Jamie Anna Michelle Katherine Bertha

Manuel Katherine Michelle Anna Bertha Jamie

Anna David Jon Ichabod Manuel Austin

Bertha Jon David Austin Manuel Ichabod

Jamie Manuel Ichabod Jon Austin David

Katherine David Austin Manuel Ichabod Jon

Michelle Manuel Jon Ichabod Austin David

what else do we need
What else do we need?
  • Finds a person by name
  • If it doesn’t exist, it returns NULL
  • Prototype:

struct PersonType* find(struct PersonType*[],

char* name);

  • We won’t implement this function – assume that it works
loader pseudo code
Loader Pseudo Code

1) Read first line

int num = how many to read

Each string is a person’s name, add them to the array of structures

2) Do (1) one more time

3) For (i = 0; i < num; i++)

read name

find name in the list of pointers

for (j = 0; j < num; j++)

Read next person on preference list

Find the person pointer

Add person to name’s preference list

4) Do (3) one more time

ad