• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

how to solve this problem using java

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
This is the problem I am stuck with right now.
I have two array lists one producer array list and one consumer array list denoted by a and b
P1 P2 P3 P4 P5
5 6 7 8 9
C1 C2 C3 C4 C5
2 3 4 5 6
Now we find all those producer consumer pairs which satisfy the criteria Pi>=Ci
We have the following sets
(5,2)(6,2)(7,2),(8,2),(9,2)
(5,3)(6,3)(7,3),(8,3),(9,3)
(5,4)(6,4)(7,4),(8,4),(9,4)
(5,5)(6,5)(7,5),(8,5),(9,5)
(6,6)(7,6)(8,6),(9,6)
Let us done each of them with Si
so we have S1,S2,S3,S4,S5
we assign a third parameter called weight to each element in Si which has satisfied the condition Pi>=Ci;
so we we will have
(5,2,ai),(6,2,bi),(7,2,ci)....etc for S1
similarly for S2 and so on.
We need to find in each set Si the the pair which has the smallest weight.
if we have (5,2,3) and (6,2,4) then 5,2,3 should be chosen.We should make sure that there is only one pair in every set which is finally chosen on the basis of weight.
Suppose we get a pair (5,2,3) in S1 and (5,2,3) in S2 we should see that (5,2,3) is not used to compare to compare with any other elements in the same set S2,
Finally we should arrive at the best element pair in each set.They should be non repeating in other sets.
Given a problem
P0 P1 P2 P3 P4
9 5 2 2 8
6 5 4 5 3
C0 C1 C2 C3 C4

we have So as (P0,C0) and (P4,C0)
assuming that the one with the smaller index has lesser weight PO is selected.In the program I have used random weights.from set S1 we select the pair PO,CO
S1 =(P0,C1),(P1,C1) and (P4,C1)
since P0 and P4 are already used in previous set we dont use them for checking in S1 so we have (P1,C1) as best.
S2=(P0,C2),(P1,C2) and (P4,C2) so we dont use P0,C2 and P1 and C2 because PO and P1 are already used in S1.
So we choose P4,C2
in S3 and S4 ae have (P0,C3),(P1,C3),(P4,C3) so we dont choose anything
and same in S4 also.
So answer is
(P0,C0),(P1,C1) and (P4,C2).
My program is trying to assign weights and I am trying to print the weights along with the sets.It doesnt work fine.I need help to write this program to do this.
Thanks.
Regards.
NP
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch!
I don't think you're going to get any answers to this, because it's quite long and complicated but doesn't actually ask a question. Can you narrow this down somewhat, perhaps show a small amount of code (please use the UBB "CODE" tags) and then ask a specific question along the lines of "How do I do X in Java" and try again?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic