-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Files
- Loading branch information
Showing
4 changed files
with
488 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import javax.print.attribute.Size2DSyntax; | ||
import java.util.Hashtable; | ||
import java.util.Random; | ||
|
||
public class disjointSet { | ||
Hashtable<Integer,Double>internalDif=new Hashtable<>(); | ||
Hashtable<Integer,Integer>PARENT=new Hashtable<>(); | ||
Hashtable<Integer,Integer>RANK=new Hashtable<>(); | ||
Hashtable<Integer,Integer>SIZE=new Hashtable<>(); | ||
|
||
public disjointSet(Integer[] universe){ | ||
for(Integer x:universe){ | ||
PARENT.put(x,x); | ||
RANK.put(x,0); | ||
internalDif.put(x,0.0); | ||
SIZE.put(x,1); | ||
} | ||
} | ||
|
||
public Integer find(Integer item){ | ||
if(PARENT.get(item)==item){ | ||
return item; | ||
} | ||
else{ | ||
PARENT.replace(item,find(PARENT.get(item))); | ||
return find(PARENT.get(item)); | ||
} | ||
} | ||
|
||
public int getSize(Integer item){ | ||
return SIZE.get(find(item)); | ||
} | ||
|
||
public void union(Integer a, Integer b,double edgeWeight){ | ||
int x=find(a); | ||
int y=find(b); | ||
if(x==y){ | ||
return; | ||
} | ||
if(RANK.get(x)>RANK.get(y)){ | ||
int childSize=SIZE.get(y); | ||
PARENT.replace(y,x); | ||
int curSize=SIZE.get(x); | ||
curSize=curSize+childSize; | ||
SIZE.replace(x,curSize); | ||
setInternalDif(x,edgeWeight); | ||
}else if(RANK.get(y)> RANK.get(x)){ | ||
int childSize=SIZE.get(x); | ||
PARENT.replace(x,y); | ||
int curSize=SIZE.get(y); | ||
curSize=curSize+childSize; | ||
SIZE.replace(y,curSize); | ||
setInternalDif(y,edgeWeight); | ||
} | ||
else { | ||
int childSize=SIZE.get(x); | ||
PARENT.replace(x,y); | ||
int curSize=SIZE.get(y); | ||
curSize=curSize+childSize; | ||
SIZE.replace(y,curSize); | ||
int replace=RANK.get(y); | ||
replace++; | ||
RANK.replace(y,replace); | ||
setInternalDif(y,edgeWeight); | ||
} | ||
|
||
} | ||
|
||
public void setInternalDif(Integer x,double value){ | ||
Integer parent=find(x); | ||
internalDif.replace(parent,value); | ||
} | ||
|
||
public double getInternalDif(Integer x){ | ||
Integer parent=find(x); | ||
return internalDif.get(parent); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
public class edge { | ||
private int greenWeight; | ||
private int redWeight; | ||
private int blueWeight; | ||
private int rgbWeight; | ||
private vertex vertex1; | ||
private vertex vertex2; | ||
private int pixelPlacement1; | ||
private int pixelPlacement2; | ||
|
||
//edge has a weight, and the 2 vertices it connects | ||
|
||
public edge(vertex vertex1, vertex vertex2,int width){ | ||
this.vertex1=vertex1; | ||
this.vertex2=vertex2; | ||
this.pixelPlacement1=vertex1.getxValue()+(vertex1.getyValue()*width); | ||
this.pixelPlacement2=vertex2.getxValue()+(vertex2.getyValue()*width); | ||
greenWeight=vertex2.getGreenValue()-vertex1.getGreenValue(); | ||
redWeight=vertex2.getRedValue()-vertex1.getRedValue(); | ||
blueWeight=vertex2.getBlueValue()-vertex1.getBlueValue(); | ||
int redDif=(vertex2.getRedValue()-vertex1.getRedValue())*(vertex2.getRedValue()-vertex1.getRedValue()); | ||
int blueDif=(vertex2.getBlueValue()-vertex1.getBlueValue())*(vertex2.getBlueValue()-vertex1.getBlueValue()); | ||
int greenDif=(vertex2.getGreenValue()-vertex1.getGreenValue())*(vertex2.getGreenValue()-vertex1.getGreenValue()); | ||
rgbWeight=redDif+blueDif+greenDif; | ||
} | ||
|
||
public vertex getVertex1(){ | ||
return vertex1; | ||
} | ||
|
||
public int getPixelPlacement1(){ | ||
return pixelPlacement1; | ||
} | ||
|
||
public int getPixelPlacement2(){ | ||
return pixelPlacement2; | ||
} | ||
|
||
public vertex getVertex2(){ | ||
return vertex2; | ||
} | ||
|
||
public int getGreenWeight(){ | ||
return greenWeight; | ||
} | ||
|
||
public int getRedWeight(){ | ||
return redWeight; | ||
} | ||
|
||
public int getBlueWeight(){ | ||
return blueWeight; | ||
} | ||
|
||
public double getRgbWeight(){ | ||
return rgbWeight; | ||
} | ||
} |
Oops, something went wrong.