Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

stable marriage problem

Posted on 2003-02-19
13
Medium Priority
?
1,639 Views
Last Modified: 2012-05-04
I'm struggling to get the stable marriage problem solved in java. I have two arrays of point3d's and have a list of all the possible distances in rank order, but i can't get the algorithm to work. Can any1 help please
Cheers
0
Comment
Question by:n0152974
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 7984597
Please post your code so far
0
 

Author Comment

by:n0152974
ID: 7984628
   public void stableMarriage()
    {
        AvailableIndex [] startAvailableIndex = new AvailableIndex[start.length];
        for(int b = 0; b < startAvailableIndex.length; b++)
        {
            startAvailableIndex[b] = new AvailableIndex();
        }
        while(!allPaired(startAvailableIndex))
        {
               System.out.println("in while loop");
            //pick 1st unpaired
            int i = 0;
            for(i=0;i<start.length;i++)
            {
                if(startAvailableIndex[i].index() == -1)
                {
                    break;
                }
               
            }
               PointDist temp;
               if(startAvailableIndex[i].index == -1)
               {
                 temp = lists[i][0]; //get first choice
               }
               else
               {
                    temp = lists[i][startAvailableIndex[i].index()];
               }
               startAvailableIndex[i].increment();
            //remove lists[i][0] and shift then all down
               System.out.println("temp "+temp.toString());
            if(temp.available()==true)
            {
                    System.out.println(temp.toString());
                if(temp.dist() <= start [i].distance( end[startAvailableIndex[i].index()] )  )
                {
                    //makePair(start[i],temp);
                         startAvailableIndex[i].available = false;
                }
                    else
                    {
                         //remain unpaired
                         //startAvailableIndex[i] = -1;
                    }              
            }
        }
          for(int b = 0; b < startAvailableIndex.length; b++)
        {
            System.out.println(startAvailableIndex[b].index());
        }
    }
   
    public boolean allPaired(AvailableIndex [] temp)
    {
          System.out.println("All paired");
        for(int b = 0; b < temp.length; b++)
        {
            if(temp[b].available() == true)
            {
                return false;
            }
        }
        return true;
    }
0
 

Author Comment

by:n0152974
ID: 7984640
AvailableIndex is a class containing a boolean representing available, int (index) and float (distance)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:danBosh
ID: 7984800
all you need to do is bosh
0
 

Author Comment

by:n0152974
ID: 7986705
any other constuctive comments please?
0
 

Author Comment

by:n0152974
ID: 7993422
is it possible for me to do this problem or is another way needed?
0
 

Author Comment

by:n0152974
ID: 8003966
can any1 help me please?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8004039
0
 

Expert Comment

by:SpideyMod
ID: 8104364
A request for refund has been made.  Experts you have 72 hours to respond.

danBosh,
I have seen many of your responses that say "all you need to do is bosh".  If you have nothing professional or constructive to add to a question, do not post.  This will be your only warning.

SpideyMod
Community Support Moderator @Experts Exchange
0
 

Expert Comment

by:danBosh
ID: 8105494
Sorry SideyMod, n0152974 is my flatmate, and the comment was only a joke
0
 

Expert Comment

by:danBosh
ID: 8105495
Sorry SideyMod, n0152974 is my flatmate, and the comment was only a joke
0
 

Expert Comment

by:SpideyMod
ID: 8105550
danBosh,
Thanks for responding.

SpideyMod
Community Support Moderator @Experts Exchange
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8132680
PAQ'd and points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question