id
stringlengths
36
36
text
stringlengths
1
1.25M
6ee8dd73-6cee-4d6e-bfe9-f66aecc3f545
public Card(Suit p_suit, Rank p_rank) { this.suit = p_suit; this.rank = p_rank; // System.out.println(this.suit); }
06642057-210c-4d4a-aa0a-2ec062219b78
public Suit getSuit() { return suit; }
31afbdd4-855f-4028-94ac-59346da7791a
public Rank getRank() { return rank; }
1b7bee49-7c6b-4c67-b07d-affb38fe0972
public Card getCard() { return new Card(suit, rank); }
c3f193c3-8337-43dd-8e13-af6307f6f57c
void calculateSum();
efada3b1-bb9d-431d-8902-0564dcbafd65
int addValue(int value);
ec722840-239a-4e69-bcd5-5e6f7e754d74
void replaceValue(int newValue, int index);
c6992ef7-ae15-4b10-812a-3fe816a2bfb9
void deleteValue(int index);
708f0f64-96cd-40d9-b60f-3658eda2f277
int getLength();
5aa0461c-68d6-48af-b030-6b5d7352d508
int getRandomMember();
a132c79f-4e6e-4581-be88-9d8dd2589215
int getSum();
b8cded1c-35a2-4d9f-84d9-ca138a56a3e5
int getValue(int index) throws Exception;
0beab57e-cca4-4947-bf08-4d849e7fa4cd
int[] getValues();
8dcfbbf2-80bb-48e8-b1ec-45e1dcc6b344
void refreshSum();
1b238800-f08a-4dff-82e9-881308190a91
Set getCopy();
c99dc573-bf59-4e43-9dfb-2e0c6657434a
public Set(int length) { this.counter = 0; this.length = length; this.sum = 0; this.values = new int[length]; this.refreshed = true; }
7177b4ce-407d-452b-a0d3-e0dc41d6927a
@Override public void calculateSum() { for (int i = 0; i < length; i++) { sum += values[i]; } }
c81485ca-51df-4f28-82bf-fcab81b7ab39
@Override public int addValue(int value) { values[counter] = value; this.refreshed = false; return counter++; }
6f2f118f-b592-46da-ba40-0427a4b589e1
@Override public void replaceValue(int newValue, int index) { values[index] = newValue; this.refreshed = false; }
ec73dce7-8ed3-496e-8cc0-35b4bf75cfd8
@Override public void deleteValue(int index) { while(index < counter) { values[index] = values[index+1]; index++; } counter--; this.refreshed = false; }
e795a8bf-32ab-442b-9a1a-138c86286d16
@Override public int getLength() { return length; }
7e8bdece-c4c0-4c9c-b742-8bdaf723582b
@Override public int getRandomMember() { return (int) (Math.random()*length); }
44c04654-c4b3-44b2-b31f-4cddcaafe365
@Override public int getSum() { if (this.refreshed == false) { refreshSum(); } return sum; }
22512c77-1a98-4449-9ff3-051b0c779926
@Override public int getValue(int index) throws Exception { if (index >= values.length) { System.out.println("Current solution has no upper neighbor."); return values[index-1]; } if (index < 0) { System.out.println("Current solution has no lower neighbor."); return values[0]; } return values[inde...
c8a724aa-5104-4b43-a8fd-d2f9c9f47072
@Override public int[] getValues() { return this.values; }
9c5ad1f4-a068-41b5-97da-346298aacf10
@Override public void refreshSum() { sum = 0; calculateSum(); this.refreshed = true; }
3a84b111-9789-4640-9f81-8fe02410a6cf
@Override public Set getCopy() { Set copy = new Set(this.length); copy.counter = this.counter; copy.length = this.length; copy.sum = this.sum; copy.values = this.values.clone(); copy.refreshed = this.refreshed; return copy; }
e4411875-8927-4d6e-917a-5f0e108384d5
@Before public void initialize() { s = new Set(2); s.addValue(5); s.addValue(15); }
f121ff65-4dc7-4ea1-a2a3-16b2e7baf6f7
@After public void cleanUp() { s = null; }
d51b2df9-84bf-4c11-9e24-ad2576a7e58b
@Test public void testGetLength() { assertEquals(2, s.getLength()); }
281000da-d570-4770-b938-03dd2169d7bd
@Test public void testAddValue() { try { assertEquals(5, s.getValue(s.addValue(5))); assertEquals(15, s.getValue(s.addValue(15))); } catch (Exception e) { e.printStackTrace(); } }
3cf24151-4beb-4f59-b783-fa28b9764403
@Test public void testReplaceValue() { s.replaceValue(25, 0); try { assertEquals(25, s.getValue(0)); } catch (Exception e) { e.printStackTrace(); } }
44ed16a8-f373-4b9e-b58a-844fc16db5dd
@Test public void testDeleteValue() { s.deleteValue(0); try { assertEquals(15, s.getValue(0)); } catch (Exception e) { e.printStackTrace(); } }
4fb6c6a9-133a-4dfb-bb39-5008bfa38f4d
@Test public void testCalculateSum() { s.calculateSum(); assertEquals(20, s.getSum()); }
7fe0342b-e02b-4278-b6ae-bd59da2ceb04
@Test public void testGetRandomMember() { assertNotNull(s.getRandomMember()); }
c66eca68-f0eb-453a-81c2-da68815597b8
@Test public void testGetCopy() { Set copy = s.getCopy(); assertArrayEquals(s.getValues(), copy.getValues()); assertEquals(s.getLength(), copy.getLength()); assertEquals(s.getSum(), copy.getSum()); }
353dcced-3569-4f3e-98e6-5790e3a4bd83
@Override public void defineInitialState() { // TODO Auto-generated method stub }
9b21da2c-f215-4ff2-bf88-835aa1d8d1a6
@Override public int computeFitnessValue(Set s1, Set s2) { // TODO Auto-generated method stub return 0; }
24da0946-829a-40bf-b5f8-7dc52194d836
@Override public void startNeighborhoodSearch() throws Exception { // TODO Auto-generated method stub }
c3473680-2898-499b-8656-f828a02a50f9
@Override public void computePossibleSolutions() throws Exception { // TODO Auto-generated method stub }
100c2cc9-b4b2-4b56-948f-828fc08ed86b
@Override public void findMinimum() throws Exception { // TODO Auto-generated method stub }
adfb8ae7-86d3-4c97-afc1-f5373fd41738
@Override public void updateSolution(int indexSubsetOne, int indexSubsetTwo) throws Exception { // TODO Auto-generated method stub }
6fded7f5-0c22-481b-a350-6e61b8f8b002
@Override public void pickRandomSolution() { // TODO Auto-generated method stub }
4af87914-1837-4179-b32e-0bfcd211545a
@Override public int[] getCurrentSolution() throws Exception { // TODO Auto-generated method stub return null; }
d06554a0-0718-456e-b6cc-f65c65bb2b01
@Override public Set getSubsetOne() { // TODO Auto-generated method stub return null; }
1aa2687f-71f9-4d88-ae5f-3ae75746d0fa
@Override public Set getSubsetTwo() { // TODO Auto-generated method stub return null; }
e09c7c5a-2deb-481c-862b-9d855fab8d5f
@Override public int getFitnessValue() { // TODO Auto-generated method stub return 0; }
301d8dd9-ccd2-4fde-b466-5b2841fce8d1
@Override public int[] getPossibleSolutions() { // TODO Auto-generated method stub return null; }
ac9af825-5622-47b6-bd34-3b779e2b7caa
@Override public void printPossibleSolutions() { // TODO Auto-generated method stub }
169a525f-cb22-46b7-a302-1a9307dff760
void defineInitialState();
28a9a97e-0122-4bc5-af5a-44412f48ab54
int computeFitnessValue(Set s1, Set s2);
c13892f7-1778-413c-bd55-d293d28fe159
void startNeighborhoodSearch() throws Exception;
e7dbbb1f-e481-413b-bf36-f4a03033e679
void computePossibleSolutions() throws Exception;
8f09ba59-5e2d-4bd9-9ec4-5497fecc73c3
void findMinimum() throws Exception;
c6f0c510-ac32-4230-93ae-157d04294ea3
void updateSolution(int indexSubsetOne, int indexSubsetTwo) throws Exception;
a10fc042-6b76-45c2-bb8c-f26114e3e594
void pickRandomSolution();
def48278-794c-4744-b566-e9309b0d411e
int[] getCurrentSolution() throws Exception;
ac40c2da-91f7-4f6e-8cc6-ccd11c37a113
Set getSubsetOne();
35b1e577-abe5-4be7-8418-3533a370fe0e
Set getSubsetTwo();
6bd170ff-b938-4275-8b6d-fbe90d4afd63
int getFitnessValue();
c842c141-bccc-4380-aa5b-44e63ce7ce8d
int[] getPossibleSolutions();
b10fceb3-1ff9-4853-889b-7593eb292e12
void printPossibleSolutions();
ad54c954-e09c-4d34-8adf-c9d3bf80ad37
public OutputPane() { frame = new JFrame("Search Output"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setComponents(); showPane(); }
56d393bb-7f1d-4fc6-8df7-3accd4964aab
private void setComponents() { sizeOfParentSetLabel = new JLabel("Specify the parent set's size: "); labelX1 = new JLabel("x1 = "); labelX2 = new JLabel("x2 = "); labelX3 = new JLabel("x3 = "); labelX4 = new JLabel("x4 = "); labelX5 = new JLabel("x5 = "); labelX6 = new JLabel("x6 = "); labelX7 = new JLa...
d0f10ccc-19c3-45b9-a99f-682768921518
public void actionPerformed(ActionEvent e) { resetLabels(); try { sizeOfParentSet = Integer.parseInt(inputField.getText()); } catch (NumberFormatException nfe) { nfe.printStackTrace(); showMissingInputValueDialog(); } HillClimberImplementation.startAlgorithm(); }
8a7bee42-bfef-45f3-b905-5ae3a3a3f6af
private void showPane() { frame.pack(); frame.setVisible(true); }
5a928846-ee4f-44f5-b03f-d754501acb62
public int getSizeOfParentSet() { return sizeOfParentSet; }
8a0a5099-536a-4a86-b944-4865105e7ca4
public void setLabels(int label1, int label2, int label3, int label4, int label5, int label6, int label7, int label8) { labelSolutionX1.setText(""+label1); labelSolutionX2.setText(""+label2); labelSolutionX3.setText(""+label3); labelSolutionX4.setText(""+label4); labelSolutionX5.setText(""+label5); labelSol...
28dc50b6-9112-4c00-b526-cafb5d37ccee
public void setCurrentSolutionLabel(int currentSolutionLabel) { currentSolutionValue.setText(""+currentSolutionLabel); }
fe56afe2-6723-44e0-bb24-2368eb4ee33b
public void resetLabels() { labelSolutionX1.setText(""); labelSolutionX2.setText(""); labelSolutionX3.setText(""); labelSolutionX4.setText(""); labelSolutionX5.setText(""); labelSolutionX6.setText(""); labelSolutionX7.setText(""); labelSolutionX8.setText(""); currentSolutionValue.setText(""); }
aca8f232-e1db-4a63-b331-accbb0919359
public void showMissingInputValueDialog() { JOptionPane.showMessageDialog(frame, "Please specify a feasible value.", "Message", JOptionPane.WARNING_MESSAGE); }
7d28e554-7db7-46e4-92dd-b522d5947fd0
public void showLocalMinimumDialog() { JOptionPane.showMessageDialog(frame, "Cannot reach a better local minimum.", "Message", JOptionPane.WARNING_MESSAGE); }
43434c63-501d-42b2-bdff-30b9e75e8113
public void showGlobalMinimumDialog() { JOptionPane.showMessageDialog(frame, "Reached global minimum."); }
9db64900-e935-4c3b-8a1f-3928fd83ea60
public HillClimber(Set parentSet) { this.parentSet = parentSet; possibleSolutions = new int[8]; pending = true; reachedLocalMinimum = true; numberOfRuns = 0; }
96a81c8b-bec9-4f79-af9f-309690fa8e4f
@Override public void defineInitialState() { subSetOne = new Set(parentSet.getLength()/2); subSetTwo = new Set(parentSet.getLength()/2); for (int i = 0; i < parentSet.getLength(); i++) { int randomNumber = (int) (Math.random()*20+1); if (i%2 == 0) { subSetOne.addValue(randomNumber); } else...
bd713cbf-8b7f-4a56-949e-3f77b4dc5435
@Override public int computeFitnessValue(Set s1, Set s2) { // Fitness value = difference between the sums of the sets' values fitnessValue = s1.getSum() - s2.getSum(); return s1.getSum() - s2.getSum(); }
7d541152-90ff-47e8-acca-f3af83ee0830
@Override public void startNeighborhoodSearch() throws Exception { do { computePossibleSolutions(); if (pending == false) { break; } printPossibleSolutions(); findMinimum(); } while(pending == true); }
53074381-214f-4aef-96be-749bebb084af
@Override public void computePossibleSolutions() throws Exception { int counter = 0; int loopIndexSubsetOne = 0; int loopIndexSubsetTwo = 0; System.out.println("Current solution: " + fitnessValue); if (fitnessValue == 0) { pending = false; System.out.println("Current solution is optimal."); } ...
4d1d834d-8366-4876-90b2-b145ad973bf6
@Override public void findMinimum() throws Exception { int localMinimumIndex = 0; pending = false; reachedLocalMinimum = true; System.out.println('\n' + "##### Run: " + numberOfRuns + " ######"); for (int i = 0; i < possibleSolutions.length; i++) { if (Math.abs(possibleSolutions[i]) < Math.abs(...
ca17a323-fb8b-4fcb-a1a4-69458c477e0e
@Override public void updateSolution(int indexSubsetOne, int indexSubsetTwo) throws Exception { int dummySubsetOne = subSetOne.getValue(indexSubsetOne); int dummySubsetTwo = subSetTwo.getValue(indexSubsetTwo); subSetOne.replaceValue(dummySubsetTwo, indexSubsetOne); subSetTwo.replaceValue(dummySubsetOne, ind...
7c7e8706-6617-4f5f-9393-9614e4f11a19
@Override public void pickRandomSolution() { currentSolutionSubsetOne = subSetOne.getRandomMember(); currentSolutionSubsetTwo = subSetTwo.getRandomMember(); }
67133147-c076-4bce-b23b-cbcdc1db8e91
public void setRandomSolution(int indexSolutionSubsetOne, int indexSolutionSubsetTwo) { currentSolutionSubsetOne = indexSolutionSubsetOne; currentSolutionSubsetTwo = indexSolutionSubsetTwo; }
a4f3984a-8737-41dc-a625-cf376d1638a0
@Override public int[] getCurrentSolution() throws Exception { int[] resultArray = new int[2]; resultArray[0] = currentSolutionSubsetOne; resultArray[1] = currentSolutionSubsetTwo; return resultArray; }
e8bc05c9-c027-45aa-bedc-334f1649bc8b
@Override public Set getSubsetOne() { return subSetOne; }
d6dc5944-035c-4201-8886-c784b6911d77
@Override public Set getSubsetTwo() { return subSetTwo; }
c92e20c7-51e8-4da9-a5a3-cc78cc680cf6
@Override public int getFitnessValue() { return fitnessValue; }
f7ea6b57-7252-4a47-a50e-cf14426ce04a
@Override public int[] getPossibleSolutions() { return possibleSolutions; }
b09be2c6-c6bd-47e2-a31d-c27bed280efb
public boolean getPending() { return pending; }
8d29e1a3-b6e0-48fc-b479-ce56dd534412
public boolean getReachedLocalMinimum() { return reachedLocalMinimum; }
8c2b6aca-ee4a-4c4d-99f4-d631d048693d
@Override public void printPossibleSolutions() { for (int i = 0; i < possibleSolutions.length; i++) { System.out.println(getPossibleSolutions()[i]); } }
cb5551ae-8858-4864-8ab8-1f7d90795d13
public static void main(String[] args) { gui = new OutputPane(); }
6043ffd6-46cf-492b-b966-d1dff9c300ea
public static void startAlgorithm() { try { getInitialInformation(); Set parent = new Set(parentSetLength); hc = new HillClimber(parent); } catch (IOException e) { e.printStackTrace(); } hc.defineInitialState(); try { hc.pickRandomSolution(); System.out.println("Random pick subset1: ...
46a398d0-9768-499d-a4e8-c2b60fa24f2b
private static void getInitialInformation() throws IOException { parentSetLength = gui.getSizeOfParentSet(); }
7ee525a7-7a69-4869-a159-1aeeb7174dbc
private static void startNeighborhoodSearch() throws Exception { new Thread() { @Override public void run() { try { do { Thread.sleep(2000); hc.computePossibleSolutions(); setLabels(); hc.printPossibleSolutions(); if (hc.getPending() == false) { ...
4eacd92c-daaa-4ffb-b691-f5d28cc05af2
@Override public void run() { try { do { Thread.sleep(2000); hc.computePossibleSolutions(); setLabels(); hc.printPossibleSolutions(); if (hc.getPending() == false) { break; } hc.findMinimum(); if (hc.getReachedLoca...
8cf4036b-dfb6-42fb-859f-9db43199af30
private static void setLabels() { int[] labelInput = hc.getPossibleSolutions(); gui.setLabels(labelInput[0], labelInput[1], labelInput[2], labelInput[3], labelInput[4], labelInput[5], labelInput[6], labelInput[7]); gui.setCurrentSolutionLabel(hc.getFitnessValue()); }
7c07713a-312d-4208-89a2-4561d7a494c0
void defineInitialState();
d1da50e0-bdaf-4d2c-96d0-4d4953357f96
int computeFitnessValue(Set s1, Set s2);
7dbf81d7-6ae8-4f5b-a5d4-d2d636662483
void startNeighborhoodSearch() throws Exception;
4ed5bdbf-a9b2-4795-8bbc-6ab3ebc583e9
void computePossibleSolutions() throws Exception;