id
stringlengths
36
36
text
stringlengths
1
1.25M
bc31862d-b96f-4cfd-8d98-1022cb0a15c4
public FileReader(String file) { this.file = file; }
2871355d-6e46-4cfb-8c28-ced4a0e74303
private List<City> createCities(int n) { List<City> cityList = new ArrayList<City>(); for (int i = 0; i < n; i++) { City city = new City(i); cityList.add(city); } return cityList; }
333dd3ff-9ea3-46fa-ad32-d1d7064e2c21
private double[][] createCityMatrix(int size, BufferedReader br) throws IOException { double[][] dMatrix = new double[size][size]; String line = null; for (int i = 0; i < size; i++) { line = br.readLine(); double[] row = new double[size]; int j = ...
a83b02a0-76cd-4302-b853-16ea5fb628b8
private DistanceMatrix readFile() { Path file = Paths.get(this.file); BufferedReader br = null; try { br = Files.newBufferedReader(file, Charset.forName("UTF-8")); int numberOfCities = Integer.valueOf(br.readLine()); List<City> cityList = createCities(numberOf...
849cbe56-a497-4b0f-a722-77f4e288ac36
@Override public DistanceMatrix read() { return readFile(); }
59f1be52-5337-47b3-a669-29c8cc76e92d
public DistanceMatrix read();
09ead944-4906-4d5b-917b-e8404bad19e1
public MockReader(int nCities) { this.nCities = nCities; }
50bbb4e5-966e-4c76-84bb-1efacbfc2c69
private List<City> createCities(int n) { List<City> cityList = new ArrayList<City>(); for (int i = 0; i < n; i++) { City city = new City(i); cityList.add(city); } return cityList; }
7be83dec-9ee4-4f72-94ef-7cf17edffc00
private double[][] createCityMatrix(int size) { double[][] dMatrix = new double[size][size]; Random r = new Random(); for (int i = 0; i < size; i++) { double[] row = new double[size]; for (int j = 0; j < size; j++) { row[j] = 1 + (100) * r.nextDouble(); ...
f5919fbb-96df-4c94-be32-326b4b72e9ba
private DistanceMatrix generateMatrix(int numberOfCities) { List<City> cityList = createCities(numberOfCities); double[][] cityMatrix = createCityMatrix(numberOfCities); return new DistanceMatrix(cityList, cityMatrix); }
f4168c78-90cd-4069-9fa8-509a23072a08
@Override public DistanceMatrix read() { return this.generateMatrix(this.nCities); }
3226fce9-ab68-444c-a1cf-8650252aa7dc
@Override public TwoCitiesSolution solveDoisViajantes(DistanceMatrix dm) { this.dm = dm; return solve(dm); }
0c4c2b23-e9ce-4fcb-97b6-c4a70387ede7
private TwoCitiesSolution[] createPartialSolution(TwoCitiesSolution tcs, City city) { TwoCitiesSolution tcs1 = new TwoCitiesSolution(tcs.getA(), tcs.getB(), tcs.getDm()); TwoCitiesSolution tcs2 = new TwoCitiesSolution(tcs.getA(), tcs.getB(), tcs.getDm()); tcs1.addToA(city); tcs2.addToB(...
85dd6970-ad5d-4f58-b897-53c9f1011da5
private Set<TwoCitiesSolution> getSolutionsWithSize(Map<TwoCitiesSolution, Double> partialSums, int size) { Set<TwoCitiesSolution> sols = new HashSet<TwoCitiesSolution>(); for (Map.Entry<TwoCitiesSolution, Double> entry : partialSums.entrySet()) { if (entry.getKey().totalNumberOfCities() == ...
4e29e650-e27d-4933-bbe4-2c7fa5d6534b
private TwoCitiesSolution getMinSumWithLength(Set<TwoCitiesSolution> sols) { TwoCitiesSolution min = null; for (TwoCitiesSolution sol : sols) { if (min == null || min.getSum() > sol.getSum()) { min = sol; } } return min; }
abbc55cc-c643-4eca-b39e-edc1a1018e35
private TwoCitiesSolution solve(final DistanceMatrix dm) { Set<TwoCitiesSolution> partialSums = new HashSet<TwoCitiesSolution>() {{ add(new TwoCitiesSolution(dm)); }}; for (City city : dm.getCities()) { Set<TwoCitiesSolution> sols = new HashSet<TwoCitiesSolution>(partialS...
ef6b3a80-31b8-4b2b-b733-fa9a3708bd8e
@Override public TwoCitiesSolution solveDoisViajantes(DistanceMatrix dm) { this.dm = dm; return solve(dm); }
ae8d3bd3-5bfc-4ce9-b679-5c47b7cfc114
private TwoCitiesSolution[] createPartialSolution(TwoCitiesSolution tcs, City city) { TwoCitiesSolution tcs1 = new TwoCitiesSolution(tcs.getA(), tcs.getB(), tcs.getDm()); TwoCitiesSolution tcs2 = new TwoCitiesSolution(tcs.getA(), tcs.getB(), tcs.getDm()); tcs1.addToA(city); tcs2.addToB(...
f4c9620c-e301-4d76-8f5b-e767e4e923d2
private TwoCitiesSolution checkBothWaysAndChooseBest(TwoCitiesSolution partial, City city) { TwoCitiesSolution sol1 = new TwoCitiesSolution(partial); TwoCitiesSolution sol2 = new TwoCitiesSolution(partial); sol1.addToA(city); sol2.addToB(city); if (sol1.getSum() > sol2.getSum()...
9b7b4167-4db9-4818-9359-af967c3dc533
private TwoCitiesSolution solve(DistanceMatrix dm) { Map<TwoCitiesSolution, Double> partialSums = new HashMap<TwoCitiesSolution, Double>(); TwoCitiesSolution solution = new TwoCitiesSolution(dm); for (City city : dm.getCities()) { solution = checkBothWaysAndChooseBest(solution, city)...
05bbb7e6-d50a-4840-a57d-2276feb53b33
public TwoCitiesSolution(SortedSet<City> A, SortedSet<City> B, DistanceMatrix dm) { this.A = new TreeSet<City>(A); this.B = new TreeSet<City>(B); this.dm = dm; }
c1c22ca6-d834-468a-ad52-2138c6f3c86d
public TwoCitiesSolution(TwoCitiesSolution sol) { this(sol.getA(), sol.getB(), sol.getDm()); }
9bb47341-0b36-4f19-b0ad-e92cf23b8318
public TwoCitiesSolution(DistanceMatrix dm) { this.A = new TreeSet<City>(); this.B = new TreeSet<City>(); this.dm = dm; }
da938a4c-79a2-457d-a7fd-b318455bc2bb
public void addToA(City city) { this.getA().add(city); }
580f7805-77f3-42b4-adfe-a4feaf1db49e
public void addToB(City city) { this.getB().add(city); }
447b0810-fcd3-4bbf-a7c6-b27aabd2692f
public int totalNumberOfCities() { return this.getA().size() + this.getB().size(); }
17b6156e-4837-4c17-bf72-d63fe2eeb232
public double getSumFromSet(SortedSet<City> set) { double sum = 0; City last = null; for (City city : set) { if (last != null) { sum += this.dm.getDistance(last, city); } last = city; } return sum; }
5d657e03-4913-4e03-a32b-64ec7aafcac7
public double getSum() { return getSumFromSet(this.getA()) + getSumFromSet(this.getB()); }
9b6fde30-86ec-4a2c-a2c4-192fcf822ae5
public SortedSet<City> getA() { return A; }
3c0250a3-21c8-4050-8e18-1d777ec5a20a
public void setA(SortedSet<City> a) { A = a; }
0188ba2b-13f8-4ccb-a1c4-7de15bddcff5
public SortedSet<City> getB() { return B; }
d5e770d0-4370-47c5-855d-0c800ffc47f4
public void setB(SortedSet<City> b) { B = b; }
c405223c-38d9-4eb6-8f8c-1fa9f881f6dd
public DistanceMatrix getDm() { return dm; }
290def55-5183-482e-a115-e0624fc3941d
public void setDm(DistanceMatrix dm) { this.dm = dm; }
bb92864e-a405-4fb9-8b7d-6f398f826bd4
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((A == null) ? 0 : A.hashCode()); result = prime * result + ((B == null) ? 0 : B.hashCode()); return result; }
8d33a377-016c-456f-a490-f01f81c3a30d
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; TwoCitiesSolution other = (TwoCitiesSolution) obj; if (A == null) { if (o...
ae3fab90-ed25-4b0b-9eee-3906b6d4934e
public TwoCitiesSolution solveDoisViajantes(DistanceMatrix dm);
dd0ceeb6-3cc3-4ba5-a6fc-a9e0576195f1
@Override public TwoCitiesSolution solveDoisViajantes(DistanceMatrix dm) { return solve(dm); }
1728f833-67fc-4ffb-9bb3-da16208905a5
private double getMinSum(Set<TwoCitiesSolution> sols) { TwoCitiesSolution minSol = null; for (TwoCitiesSolution tcs : sols) { if (minSol == null || minSol.getSum() > tcs.getSum()) { minSol = tcs; } } return minSol.getSum(); }
490b1a2a-b056-41e2-9265-5b54cba7a8c2
private Set<TwoCitiesSolution> recursiveTreeGenerator(SortedSet<City> citiesToVisit, final TwoCitiesSolution current) { if (citiesToVisit.isEmpty()) { return new HashSet<TwoCitiesSolution>() {{ add(current); }}; } Set<TwoCitiesSolution> intermediateSols =...
3b91e050-4537-4b09-a3aa-b7b384f796df
private TwoCitiesSolution solve(DistanceMatrix dm) { Set<TwoCitiesSolution> solBucket = recursiveTreeGenerator(new TreeSet<City>(dm.getCities()), new TwoCitiesSolution(dm)); TwoCitiesSolution min = null; for (TwoCitiesSolution tcs : solBucket) { if (min == null || min.getSum() > tcs....
9c9665ec-330b-4120-a97f-30972511514f
public Score(String name, int score, String song) { this.name=name; this.score=score; this.song = song; }
b38115e8-0189-4eef-be87-68aac137afca
public String toString() { return name+": "+score+" for "+song; }
2faba4fe-b989-4c7b-a681-cd2d36b32dec
public Ending(ArrayList scores) { this.scores=scores; setLayout(new GridLayout(4,4)); add(new JLabel("High scores:")); String stringScores=""; for(int i=0;i<scores.size();i++) { stringScores+=scores.get(i)+"\n"; } add(new JTextArea(stringScores)); }
d8efede3-0c13-46bd-af66-86b8e4daa0f2
public ArrayList getScores() { return scores; }
9a335bc1-1545-44d9-a166-7534938a9a24
public void addScore(Score score) { scores.add(score); }
f29d9c0b-0d13-4f15-8125-2b58a0d6fed4
public MenuScreen() { currentSong="SomeoneLikeYou"; playNow=false; diffPanel=new DifficultyPanel(); setBackground(Color.WHITE); setLayout(new BorderLayout()); add(diffPanel, BorderLayout.SOUTH); add(new SizePanel(),BorderLayout.EAST); bar=new JMenuBar(); JPanel n=new JPanel(); n.add(new SelectionP...
b072727b-6f20-4ab5-a85c-432d84016695
public void clearMenu() { if(currentSong.equals("SomeoneLikeYou")) { try { player.stopSong(); remove(player); } catch(NullPointerException e) {}; } try { remove(player); }catch(NullPointerException e) { }; int diff=diffPanel.getDifficulty(); player=new SongPlayer(diff, s...
5c608e07-45d1-4cb8-8f83-9755e167cd4b
public void paintComponent(Graphics g) { super.paintComponent(g); if(!playNow) { titleFont=new Font("SansSerif", Font.BOLD, titleFontSize); g.setFont(titleFont); g.drawString("PIANO HERO", getWidth()/2-220, getHeight()/2+50); //white piano keys: for(int i=1;i<9;i++) g.drawLine(getWidth()/9*i, ...
6bfa0e0c-aa7a-4fc7-ae94-89c97831acee
public void repaintMenu() { repaint(); }
63e36e3d-4bdc-4351-9832-7527ecbfae96
public SizePanel() { titleSizer=new JSlider(12,100,72); add(titleSizer); titleSizer.addChangeListener(this); titleSizer.setOrientation(JSlider.VERTICAL); }
4c88de07-7b4b-4edf-bd7f-7410f8f6b273
public void stateChanged(ChangeEvent evt) { titleFontSize=titleSizer.getValue(); repaintMenu(); }
11a73de0-f635-428f-8f97-ded96c407916
public SelectionPanel() { songs=new JComboBox(); songs.setFont(new Font("TimesNewRoman", Font.PLAIN,12)); songs.addItem("Someone Like You - Adele"); songs.addItem("Don't Leave Me - Regina Spektor"); disclaimer=new JLabel("More songs to be added later."); add(songs); add(disclaimer); songs.add...
b7a7252f-3c94-43ed-84ca-0b1c395de600
public void actionPerformed(ActionEvent evt) { int index=songs.getSelectedIndex(); if(index==0) currentSong="SomeoneLikeYou"; else currentSong="DontLeaveMe"; }
053e3738-9a47-4e4f-a768-56dad0d9db24
DifficultyPanel() { begin=new JButton("Begin"); quit=new JButton("Quit"); easy=new JCheckBox("Easy"); easy.setSelected(false); medium=new JCheckBox("Medium"); medium.setSelected(false); difficult=new JCheckBox("Difficult"); difficult.setSelected(true); //listen to buttons easy.ad...
a5d27e0a-888c-41c5-ab0f-ecedd564e9d5
public int getDifficulty() { if(easy.isSelected()) return SongPlayer.EASY; if(medium.isSelected()) return SongPlayer.MEDIUM; else return SongPlayer.HARD; }
001941fb-6903-472a-a312-0ccdeb84d0cb
public void actionPerformed(ActionEvent evt) { Object source=evt.getSource(); String command = evt.getActionCommand(); //makes sure only one box is selected at a time: if(source==easy) { easy.setSelected(true); if(medium.isSelected()) medium.setSelected(false); if(difficult.isSelected())...
eb03ef0c-4406-414c-aedd-e8f9b8dd1de0
public void mouseClicked(MouseEvent arg0) { requestFocus(); }
9cb3ab72-860a-48c5-a22b-a1a74636bdbb
public void focusGained(FocusEvent arg0) {}
b62848cf-fd97-46e3-8a87-f3582cd5a802
public void focusLost(FocusEvent arg0) {}
3b772fe3-6a46-4382-8986-aa3293f65fc6
public void mouseEntered(MouseEvent arg0) {}
3dc23985-375a-404b-a921-92ad0c9940a7
public void mouseExited(MouseEvent arg0) {}
96552cdb-5f76-4604-9672-ae4eb38811e2
public void mousePressed(MouseEvent arg0) {}
c8f038d3-e55b-4fc7-9462-7e4f77104b0a
public void mouseReleased(MouseEvent arg0) {}
cd566c1e-37c8-461d-9c47-1c0a6c0d7ee0
public static void main(String[] args) { JFrame window=new JFrame("Sing us a song, you're the Piano Hero"); window.setContentPane(new MenuScreen()); window.setLocation(100,75); window.setSize(22*40,22*20); window.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); window.setVisible(true); }
22b2b8ab-7c96-4ea3-ac12-2a98ab9d5c5f
public void stopSong() { player.stop(); }
e0f6b803-ce9f-4672-8b6d-1813be9b67fc
public SongPlayer(int difficulty, ArrayList scores,String songName) { this.songName=songName; this.scores=scores; songCanPlay=true; SongLibrary lib=new SongLibrary(difficulty); setBackground(Color.WHITE); if(songName.equals("SomeoneLikeYou")) { currentSong=lib.getSLO(); msbp=214*(3-difficulty); ...
4fc837b6-dfe9-47fa-8b9d-16b6b237e42a
public void paintComponent(Graphics g) { if(songCanPlay) { super.paintComponent(g); //Constant background things: for(int i=1;i<9;i++) g.drawLine(getWidth()/9*i, 0, getWidth()/9*i, getHeight()); g.drawString("a", getWidth()*1/9, getHeight()-10); g.drawString("s", getWidth()*2/9, getHeight()-10);...
e23b7ea3-126a-48c1-800f-8461292ec53c
public void endScreen(ArrayList scores) { if(songName.equals("SomeoneLikeYou")) player.stop(); else p.stop(as); songCanPlay=false; repaint(); setLayout(new BorderLayout()); Ending end=new Ending(scores); add(end,BorderLayout.CENTER); revalidate(); }
739a7747-9b9f-40b2-8d53-1d2cfe7e3f56
public boolean isPlaying() { return songCanPlay; }
aca024a8-4f51-4fba-ac7b-d037e94b0239
public void actionPerformed(ActionEvent evt) { startValue++; repaint(); }
fc794596-9ac4-4ba6-aecf-a4e221eb0f04
public void keyPressed(KeyEvent evt) { int key=evt.getKeyCode(); if (key==KeyEvent.VK_A) { if(currentBeat.a) { score+=20; currentBeat.color=Color.GREEN; } else { score-=20; currentBeat.color=Color.RED; } } if (key==KeyEvent.VK_S) { if(currentBeat.s) { score+=20;...
572e6ef3-ee85-430a-835c-7f079809b877
public void mouseClicked(MouseEvent arg0) { requestFocus(); if(songCanPlay) { if(songName.equals("SomeoneLikeYou")) player.start(); else { p.start(as); } timer.start(); } }
964e9ca8-3fb4-4f86-9158-029883def688
public void keyReleased(KeyEvent arg0) {}
7442d30a-3f2b-4dc2-b5e0-9768698ab95e
public void keyTyped(KeyEvent arg0) {}
3522c0e7-1e61-44ae-9c82-7d8e0ed4d111
public void focusGained(FocusEvent arg0) {}
993ac763-1e9e-4427-95e1-04cb8553890e
public void focusLost(FocusEvent arg0) {}
8b04e4bc-1580-4a0b-a0cb-0058581a1898
public void mouseEntered(MouseEvent arg0) {}
7afe97d4-38f0-41f6-b627-d609f7706944
public void mouseExited(MouseEvent arg0) {}
69c82af7-945b-4b46-97d9-bb7f4b603e4d
public void mousePressed(MouseEvent arg0) {}
43ab7dd1-67f8-4156-8e5a-3fa3207e8bad
public void mouseReleased(MouseEvent arg0) {}
23ea04f5-2627-46d6-94cc-c1b3eb51ddaa
public Song(int difficulty, float tempo) { beats=new ArrayList<Beat>(); tempo=this.tempo/(3-difficulty); }
6c83998a-d44b-4a35-a59e-6b8638530c16
public void add(Beat beat) { beats.add(beat); }
32d11ca0-737d-4902-a22a-0a336c661a56
public ArrayList getBeats() { return beats; }
d7403d1b-15cc-411c-a231-7e15a9d50322
public void empty() { add(new Beat(false, false, false, false, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, false)); ...
89f15de9-715a-49e2-9584-86a1f34fff90
public void AMajorTriad() { add(new Beat(false, false, false, true, false, true, false, false));//unison A add(new Beat(false, false, false, false, false, false, true, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, ...
3ba5fe78-db5f-486c-86ef-34154aec0df7
public void AOverAb() { add(new Beat(false, false, true, false, false, true, false, false));//unison A add(new Beat(false, false, false, false, false, false, true, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, false...
a5f068fb-e32c-4a60-927f-e088b711c64c
public void FSharpMinor() { add(new Beat(false, true, false, false, true, false, false, false));//unison A add(new Beat(false, false, false, false, false, false, true, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, f...
93a7d189-06a0-431b-bf21-14178e9160bf
public void DMajor() { add(new Beat(true, false, false, false, true, false, false, false));//unison A add(new Beat(false, false, false, false, false, false, true, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, false,...
3b90914c-6842-4cb5-9ebc-b0bb7b3b9f5e
public void EMajor() { add(new Beat(false, true, false, false, true, false, false, false));//unison A add(new Beat(false, false, false, false, false, true, false, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, false,...
00ca3515-061e-460a-8754-05d1c81b03f9
public void HalfFSharp() { add(new Beat(false, false, true, false, true, false, false, false));//unison A add(new Beat(false, false, false, false, false, false, true, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, fa...
bedc8083-1abb-4665-949c-5c746b3fa40f
public void DMajor7() { add(new Beat(true, false, false, false, true, false, false, false));//unison A add(new Beat(false, false, false, false, false, false, true, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, false...
156a248f-f95c-47ed-876f-681f721e395f
public void halfDM7() { add(new Beat(false, false, false, false, true, false, false, false));//unison A add(new Beat(false, false, false, false, false, true, false, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, fals...
90257803-5883-4d38-a2d4-eea1b39a605a
public void halfA() { add(new Beat(false, false, false, true, false, true, false, false));//unison A add(new Beat(false, false, false, false, false, false, true, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, false, ...
d119965f-b893-4b75-aaea-b850539c0ccc
public void HalfD() { add(new Beat(true, false, false, false, true, false, false, false));//unison A add(new Beat(false, false, false, false, false, false, true, false));//with C# add(new Beat(false, false, false, false, false, false, false, true));//with E add(new Beat(false, false, false, false, false, ...
5aa545b5-6d7c-4323-8554-bb9bc5d0ee32
public void fullDLMriff() { add(new Beat(false, false, false, true, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, true)); add(new Beat(false, false, false, false, false, false, false, fal...
bfb86be7-bc18-4cf8-ad2a-b92eee26c9bb
public void MostDLMriff() { add(new Beat(false, false, false, false, false, false, false, false)); add(new Beat(false, false, false, true, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, tru...
e069def8-efb3-4b2e-997f-1805c39d2d27
public void chorusRiff() { add(new Beat(false, false, false, true, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, true)); add(new Beat(false, false, false, false, false, false, false, false)...
8133c1ba-3ea6-4301-adb5-05d70a9105c8
public void transition() { add(new Beat(false, false, false, true, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, false)); add(new Beat(false, false, false, false, false, false, false, true)); add(new Beat(false, false, false, false, false, false, false, false)...
f11abd5c-4392-4c89-8806-638a2641c809
public SongLibrary(int difficulty) { SomeoneLikeYou=new Song(difficulty,SLOtempof); SomeoneLikeYou.add(new Beat(false, false, false, false, false, false, false, false)); SomeoneLikeYou.AMajorTriad(); SomeoneLikeYou.AOverAb(); SomeoneLikeYou.FSharpMinor(); SomeoneLikeYou.DMajor(); SomeoneLikeYou...