Still stuck with the same old producer consumer weight problem need help

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
What I have tried till now.
I have one more question could you help me with this.
I have an array list of this form.
package mypackage1;
import java.util.*;
public class DD
private  int P;
private  int C;
private int weight;
public void set_p(int P1)
P=P1;
public void set_c(int C1)
C=C1;
public void set_weight(int W1)
weight=W1;
public int get_p()
return P;
public int get_c()
return C;
public int get_x()
return weight;
public static void main(String args[])
ArrayList a=new ArrayList();
ArrayList min_weights_int=new ArrayList();
ArrayList rows=new ArrayList();
ArrayList temp=new ArrayList();
Hashtable h=new Hashtable();
String v;
int o=0;
DD[] d=new DD[5];
for(int i=0;i<4;i++)
d=new DD();
for(int i=0;i<4;i++)
d[i].set_p(((int)(StrictMath.random()*10 + 1)));
d[i].set_c((int)(StrictMath.random()*10 + 1));
d[i].set_weight(0);
System.out.println("Producers");
for(int i=0;i<4;i++)
System.out.println(d[i].get_p());
System.out.println("Consumers");
for(int i=0;i<4;i++)
System.out.println(d[i].get_c());
System.out.println("Weights");
for(int i=0;i<4;i++)
System.out.println(d[i].get_x());
for(int i=0;i<4;i++ )
int bi =d[i].get_c();
ArrayList row=new ArrayList();
for(int j=0;j<4;j++)
if( d[j].get_p() >=bi)
d[j].set_weight((int)(StrictMath.random()*10 + 1));
row.add("(" + bi + "," + d[j].get_p() + "," +d[j].get_x() + ")");
else
d[j].set_weight(0);
row.add("null");
rows.add(row);
System.out.println(rows);
int f=0;
for(Iterator p=rows.iterator();p.hasNext();)
temp=(ArrayList)p.next();
String S="S" +f;
h.put(S,temp);
String tt=new String();
for(int j=0;j<4;j++)
if(temp.get(j).toString() !="null")
// System.out.println("In if loop");
//System.out.println(temp.get(j).toString());
String l=temp.get(j).toString();
System.out.println(l);
//System.out.println("Comma matches" + l.lastIndexOf(","));
//System.out.println(min_weights);
f++;
for(Enumeration e=h.keys();e.hasMoreElements();)
//System.out.println("I am here");
int ii=0;
int smallest=0;
String key=(String)e.nextElement();
System.out.println("key=" + key);
temp=(ArrayList)h.get(key);
System.out.println("Array List" + temp);
for( int j=0;j<4;j++)
String l=(temp.get(j).toString());
if(l!="null")
System.out.println("l=" +l);
[\code]

In your example you selected the pair with the greatest
distance from the first set, and the pair with the least
distance from the second. I don't see how the distance
function was used.
Also it's not clear to me that there is always a solution,
and, if there is, whether consistently choosing the
furthest or the closest pairs will always work.
The most obvious approach is to systematically try
all possibilities until the answer is reached, or there
are no possibilities left. This means backtracking whenever
a point is reached where you cannot continue. In this case
backtrack one step and try another possibility at this
step. After all possible choices of the previous step,
backtrack one more step and so on.
This seems rather involved, and it probably is.
Interestingly, if you know Prolog, it is ridiculously
easy because Prolog does all the backtracking for you.
In Java, you can implement the algorithm in much the same
way as Prolog implementations do it--keep a list of all the
choice points and work through them until success or there
are none left.
If you do know Prolog, you could generate lots of random
problems and see if there is always a solution.

Similar Messages

  • I want to Facetime my Ipad from my Iphone but they are both set up with the same Apple id.  Do I need to create a new id for one of them in order to facetime with the other?

    I want to Facetime my Ipad from my Iphone but they are both set up with the same Apple id.  Do I need to create a new id for one of them in order to facetime with the other?

    You should be able to call the iPad using your Apple ID from the iPhone. When calling from iPad use the iPhone's phone number to initiate the call.

  • TS1646 Can I have an ITunes account at more than one store (ie US and UK) with the same Apple ID or do I need a second one? Thanks

    I spend time in both the US and the UK and sometimes not all apps are available in the US store which is my primary account. Can I set up a second account at the UK store with the same Apple ID?

    You'll need to set up a second account with a different Apple ID. You cannot use a single Apple ID in two different iTunes Stores at the same time.
    Regards.

  • HT4623 I am trying to update my iPad 32 with retina display and whenever I do it tells me that I am not connected to the Internet even though I am. I have tried several different wifi spots with the same results. Any suggestions would be helpful. Thanks

    I am trying to update my iPad 32 with retina display and whenever I do it tells me that I am not connected to the Internet even though I am. I have tried several different wifi spots with the same results. Any suggestions would be helpful. Thanks

    Try a reset: hold down the home button along with the power button until you see the Apple, then let go.

  • When i type in my correct password on the login screen and press enter it just goes to a blue screen for a few seconds then goes back to the same login screen again, please i need help?

    When i type in my correct password on the login screen and press enter it just goes to a blue screen for a few seconds then goes back to the same login screen again, please i need help?

    You can take some of the steps here, #4, #5 or even trying a #18
    Step by Step to fix your Mac
    but I suspect your going to first have to create a data recovery drive
    Create a data recovery, undelete boot drive
    to get your data off the machine,
    then do a #20 to eliminate the bad sectors as that's why your getting the "pinwheel" it's getting a delay reading from the drive, right when your trying to log in too, what a bad spot for it to happen.
    Step by Step to fix your Mac

  • When I save an e-mail as a file, it opens (seems stuck) to the same old one saved earlier. How do I unstick it?

    I use a MAC desktop and Thunderbird with latest update. Recently, when I've tried to open an e-mail that I saved earlier as a file with the .eml suffix, what opens is always the same unrelated e-mail that I saved earlier to an unrelated file. It seems stuck on that same unrelated e-mail, no matter what the file or what e-mail I intended to save. For example, I save (i.e., drop-down menu: Save As - File) an e-mail that I received regarding Topic A; then I go to the folder or file to which I saved it and locate the e-mail under the correct name in which I saved it; I double click and then click on Open; what always opens is an e-mail of a few months ago that I received from Bernie. It doesn't happen on my MAC Air laptop.

    Until recently, I've been able to save e-mails to files and folders by clicking "Save As" on the dropdown File menu. In the last few weeks, whenever I open any one of the many e-mails that I've saved over time as files, it doesn't open the e-mail that I'm trying to open. Instead, what opens up is always the same old email of a couple of months ago that has no relationship to the one I'm trying to open. Somehow, it's stuck on that same old e-mail. So, yes, your response is technically correct: (a) I open the message, and (b) I see what's in there. But what I always see is the same old unrelated e-mail message. My question is how do I get past that e-mail that it's stuck on to the e-mail that I saved but won't open up? Sorry to be such a pest.

  • Fed up with The same OLD APPS in App store.

    I have been staring at the same old Apps in App store since july 11th. Please developers give us some more Apps. I have read that Old jailbroken Iphones have 1000's of Apps. We have a few hundred.

    You also need to be aware that it isn't just the developer...Apple has to approve the apps before they will permit them on the iPhone. That process takes time. Only Apple approved apps are then added to the app store.
    Second, you will never see all the apps that are available on jailbroken phones because the SDK does not permit access to the phone features themselves -- if you look at those jailbroken apps, you will see all kinds of apps that access the iPod feature, the video features, the camera features. You will find bad MMS apps, you will find all kinds of things that will never be approved by Apple for the iPhone and won't end up in the official Apple App Store.
    Be patient, more applications will come, but you have to be realistic about what will and what will not be available.

  • Alias dropped but can still connect with the same

    Hi,
    I had 2 instances of sql server on server machine -
    XYZ05 (SQLServer 2008R2 which was default instance and port was 1433) and XYZ05\SQL2012 (New named instance and port was 40196)
    Due to some requirement we un-installed XYZ05 instance, team wanted to connect XYZ05\SQL2012 instance using default instance i.e. XYZ05. So, we created alias with same name and changed
    the port from 40196 to 1433 and it was working fine.
    Now, I have dropped the alias but I can still connect the server using same alias. I have checked registry, cliconfg.exe, restarted the service and server. However, I can still connect
    using the alias.
    Can you please tell what I missed to check or what could be the reason for alias still working?
    Thanks!!

    Hello,
    It's because the default port 1433 is used, that's why you can only use the machine name to connect to.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • HT4097 This article did not help me I tried it and tried it and i'm stuck with the same problem

    I am stuck in recovery mode for some wierd reason and i don't know what started it I don't know how to get out.  Its an Ipad 1 64 gig with att.  Just bought 2 new ipad mini's and apple tv becuase i had been impressed this issue is insane I can't even get it to get out of restore mode I've downloaded the same 726 m file over 50 times please help.  Frustrated and disenfranchilsed about the whole deal.  

    Frozen or unresponsive iPad
    Resolve these most common issues:
        •    Display remains black or blank
        •    Touch screen not responding
        •    Application unexpectedly closes or freezes
    http://www.apple.com/support/ipad/assistant/ipad/
    iPad Frozen? How to Force Quit an App, Reset or Restart Your iPad
    http://ipadacademy.com/2010/11/ipad-frozen-how-to-force-quit-an-app-reset-or-res tart-your-ipad
    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
     Cheers, Tom

  • Problems with Vista and Reader 8.12 - unusual problem need help

    I can't seem to find anyone to help me or any record of someone else having this problem. As soon as I install reader 8.12 on my new system (Vista) it begins 'hijacking' other files. In other words other icons on my desktop (e.g., the icon for AOL IM) turn into PDF icons and so when I try to launch an .exe file - Reader launches instead and of course tells me it can't open the file. This is so maddening. I've installed and unstalled the program several times and have rebooted. I've tried to contact Adobe but they will not provide support, I've contacted Gateway and they say it's an Adobe issue and Microsoft won't speak with me because Vista was pre-installed on the computer. If anyone has any ideas and can assist me I'd greatly appreciate it. For now I just have to leave the program uninstalled and therefore can't open any PDFs.
    Anita

    It seems that in Vista bad things may happen if you ever choose a
    program to open downloaded EXE files.
    This may help with the EXE issue:
    http://www.winhelponline.com/articles/165/1/Restore-the-exe-file-association-in-Windows-Vi sta-after-incorrectly-associating-it-with-another-application.html
    Aandi Inston

  • On part of my iPhone I have one apple ID which refuses to take my password, so I set up another Apple ID - but I am still stuck with the old user name.  How do I get rid of it without losing all the applications I already paid for?  Thanks.

    I have an apple id that i was using since september.  for some reason that user id is not working, so i created another.  but for my applications the old user id keeps coming up and i can't upgrade my apps - what do i do?

    Try here >  Frequently Asked Questions About Apple ID

  • System prefernces im stuck with the same screensaver for eternity!!

    I have had my macbook now for about 3 months and everyhting has been PERFECT!! but just recently i have been haveing truoble changing my screensaver.
    Evreytime i go to change my setting(for the screensaver) my system perfences quits, then i try to reopen it again and it quits again and asks me to report it to apple. i have and i even call them with my apple care but it still does it.( this all started after i change my scrrensaver to ituens artwork) Has anyone seen or heard of anything like this??
    ANY feedback would be awesome. thanks
      Mac OS X (10.4.8)  

    Yep sure have. It seems like when this comes up it usually is associated to using the iTunes screensaver. Try running a Spotlight search for a .plist file that contains both screensaver and iTunes. I don't have one since I've never ran the iTunes screensaver so I can't say specifically what it would be called. But it should be something like com.apple.iTunesscreensaver.plist
    If you find something along those lines Trash that .plist file and try going to your screensaver system preferences again.

  • Can I reinstall CS5.5 Design Premium to win8.1 with the same (old) license code (Laptop nr 2 crashed)

    If not, I should buy Adobe CC voor individuals (I am a one person self-employed company). Can I install this CC on multiple computers (like 3)? I don't have to work with them simultaniously. I use DW, FW, PS, Ai the most but buying 4 apps at € 25 is more expensive than the whole lot.

    2 Computer License http://forums.adobe.com/thread/977272

  • Does the zte open c receives on going software updates and bug fixes or is it stuck with the same software out of the box

    interested in firefox phone

    Sorry for being unable to assist you. If you live in a region where you can buy the Alcatel OneTouch Fire E, you may want to consider that device, since Alcatel has offered updates for the phone from Firefox OS 1.3 to Firefox OS 2.0.

  • Cranky old Mister Ron with the same old complaint

    Maybe I'm just pushing iTunes limits by trying to do a seven day a week Podcast. I'm certain that if I was a big deal televi$ion or radio network this wouldn't be happening.
    Anyway, 'Mister Ron's Basement' hasn't updated in the iTunes menu since Episode #615, and I'm now on Episode #619. The very important weekend Bowser and Spoopendyke episodes are coming up, and it would be nice to see iTunes update.
    And, once again, yes I have been pinging, and yes, the episodes do show up for subscribers.
    All 619 + episodes are freely available at:
    http://slapcast.com/users/revry
    -=-Ron-=-

    http://support.apple.com/kb/HT2109

Maybe you are looking for

  • Installing Adobe Illustrator CS2 Trial - Error 201

    When I get to the end, it says there is an error 201 and please try and install again? I've restarted computer, and its brand bloody new! And to think if i paid a grand things like this wouldnt happen...

  • Dynamically set report viewer report name

    <p>I have a CR4E application with several reports. I want to use the same viewer for each report in the app but need to change the report name based on the user's selection from a dropdown list on a form. How do I dynamically change the reportName in

  • I can't open Itunes music store - error message

    I can't open itunes music store. I tried downloading the new apple itunes updates, but my computer says that the updates have an invalid signature. My computer won't let me install the new itunes or apple quicktime to my computer. Can somebody help m

  • Will Sony HVR-Z1E HDV Cam (PAL) work with iMovie 6.0.3

    Hi I'm about to make a short film and have the possibility of hiring the Sony HVR-Z1E HDV Cam (http://www.sonybiz.net/biz/view/ShowProduct.action?product=HVR-Z1E&site=bizenGB&pageType=Overview&category=HDVCamcorders) for the shoot. Has anyone here us

  • Label Printing Problem

    Hi I created a smartform( Travel Card in PP). the label is showing in Print Preview as   1                                                            2                                                            3 but the printouts are coming as  3