Results 1 to 6 of 6
  1. #1
    bumblyb33 is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default The Assignment Problem

    Hello,

    I'm trying to figure out how to create a program that will solve the assignment problem. The idea I have is to create a 2D array, with each element holding a cost. Only certain costs would be added up and stored in variables. To calculate the sum of the costs I need to come up with a way to generate all the combinations.

    I don't know how to explain it very well, so I made tables to show what I mean.

    For example, a 3x3 matrix will produce 6 possible combinations, here are 2 of the combinations:

    Java Code:
      
       0  1  2	
    0  X      
    1     X   
    2        X
    
    cost1 = Matrix[0][0] + Matrix[1][1] + Matrix[2][2]

    Java Code:
      
       0  1  2	
    0  X   
    1        X   
    2     X
    
    cost2 = Matrix[0][0] + Matrix[1][2] + Matrix[2][1]

    (Sorry for the code fragments, couldn't think of anything else.)

    Would appreciate any help, thx!



    I'll try to explain more. I'm trying to generate all solutions where only 1 element in each row is chosen. The element in the next row cannot be in that same column. For example, (0,0) + (1,1) + (2,2) is one combination. (0,2) + (1,1) + (2,0) is another and so on.. Two elements cannot be chosen from the same rows or the same columns. I just can't figure out how to write an algorithm that will be able to give me all combinations correctly. There are a total of 6 combinations for a 3x3 matrix.
    Last edited by bumblyb33; 02-27-2009 at 11:26 AM.

  2. #2
    JVposter is offline Member
    Join Date
    Feb 2009
    Location
    Romania
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by bumblyb33 View Post
    Hello,

    I'm trying to figure out how to create a program that will solve the assignment problem. The idea I have is to create a 2D array, with each element holding a cost. Only certain costs would be added up and stored in variables. To calculate the sum of the costs I need to come up with a way to generate all the combinations.

    I don't know how to explain it very well, so I made tables to show what I mean.

    For example, a 3x3 matrix will produce 6 possible combinations, here are 2 of the combinations:

    Java Code:
      
       0  1  2	
    0  X      
    1     X   
    2        X
    
    cost1 = Matrix[0][0] + Matrix[1][1] + Matrix[2][2]

    Java Code:
      
       0  1  2	
    0  X   
    1        X   
    2     X
    
    cost2 = Matrix[0][0] + Matrix[1][2] + Matrix[2][1]

    (Sorry for the code fragments, couldn't think of anything else.)

    Would appreciate any help, thx!
    hello!

    I do not see where is the assignment problem ???
    The cost variable must be of same type that matrices elements!

    regards

  3. #3
    azzaiel's Avatar
    azzaiel is offline Member
    Join Date
    Feb 2009
    Posts
    57
    Rep Power
    0

    Default

    uhmm try using a List either ArrayList or LinkedList .. but i im not 100% sure on what you are trying to do can you provide a more detailed explanation?

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    pretend you have a one-dimensional array of { 0, 1, 2 }. how would you find all permutations? same principle.

  5. #5
    chrono25 is offline Member
    Join Date
    Feb 2009
    Posts
    10
    Rep Power
    0

    Default

    more details required....

  6. #6
    critdevil's Avatar
    critdevil is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Problem with an assignment: Backgammon game
    By Poddy in forum New To Java
    Replies: 6
    Last Post: 02-05-2009, 05:32 AM
  2. GUI First Assignment-DUE 8/1/08
    By ljk8950 in forum AWT / Swing
    Replies: 2
    Last Post: 08-01-2008, 04:23 AM
  3. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  4. assignment problem help needed
    By tiggz1980 in forum New To Java
    Replies: 2
    Last Post: 02-06-2008, 11:14 PM
  5. Cannot solve the coding problem of my assignment
    By elimmom in forum New To Java
    Replies: 3
    Last Post: 08-13-2007, 11:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •