This is problem of optimization.
I want to create bipartite graph with weighted edge..
So i have created program.
Please tell me how can i add weight to each of its edges and then from this i can calculate min. objective function.
Please reply.

import java.io.*;

class bip
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String str = new String();
	int i,j,k,n1,n2,slink,l;
	int set1[],set2[],ss1[],ss2[],e[][],w[][];
	int obj_func,x,y,count,z;
	
	public void create_set()
	{	
		//System.out.println("Enter the no. of members in set-1:");
		try
		{
			System.out.println("Enter the no.of members in set-1: ");
			n1=Integer.parseInt(br.readLine());
			System.out.println("Enter the no. of members in set-2: ");
			n2=Integer.parseInt(br.readLine());
			set1 = new int[n1];
			set2 = new int[n2];
			for(i=0;i<n1;i++)
			{
				set1[i] = i;
			}
			k=i;
			for(j=0;j<n2;i++,j++)
			{
				set2[j] = i;
			}
			l=j;
		}
		catch(Exception e1)
		{
			System.out.println("Raised:"+e1);
		}
	}
	void disp()
	{
		System.out.println("Members are in set-1 : ");
		for(i=0;i<n1;i++)
		{
			System.out.print(set1[i]+", ");
		}
		System.out.println("Members are in set-2 : ");
		for(j=0;j<n2;j++)
		{
			System.out.print(set2[j]+", ");
		}
	}
	void create_link()
	{
		try{
		System.out.println("Enter no. of links between nodes: ");
		slink = Integer.parseInt(br.readLine());
		for(i=0;i<slink;i++)
		{
			System.out.println("Enter the two members no. between u want link:");
			ss1[i]=Integer.parseInt(br.readLine());
			ss2[i]=Integer.parseInt(br.readLine());
		}}
		catch(Exception e2){System.out.println("Raised:"+e2);}
	}
	void is_bipartite()
	{
		x=1;
		count=0;
		while(x<=slink)
		{
			for(i=0;i<k;i++)
			{
				for(j=0;j<l;j++)
				{
					if((ss1[x]==set1[i]) && (ss2[x]==set2[j]))// || ((nn2[x]==nodelist1[i]) && (nn1[x]!=nodelist2[j])))
					{
					//cout<<"this graph is bipartite in nodelist1"<<endl;
					count++;
					}
					else if((ss1[x]==set2[j]) && (ss2[x]==set1[i]))// || ((nn2[x]==nodelist2[j]) && (nn1[x]!=nodelist1[i])))
					{
					//cout<<"this graph is bipartite in nodelist2"<<endl;
					count++;
					}
					else
					{
			   		//	cout<<"not bipartite"<<endl;
					}
				}
			}
		x++;
		}		
	}
	public static void main(String args[])
	{
		bip b1=new bip();
		b1.create_set();
		b1.disp();
		b1.create_link();
		b1.is_bipartite();
	}
}

Recommended Answers

All 2 Replies

start thinking object oriented, rather than using multiple arrays to hold each value and trying to juggle them to stay in synch.
That way you can create an Edge class that contains its weight (even contain several weights depending on the direction it is traveled).

http://gwt-sample-project.blogspot.com/

help and provide books and the sample projects for beginners and professionals getting update on new framework technology and programming languages like: java, gwt, flex, struts, spring, etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.