-
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.
- Loading branch information
Showing
10 changed files
with
1,095 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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>Prolab2-1</groupId> | ||
<artifactId>prolab-2-1</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>14</maven.compiler.source> | ||
<maven.compiler.target>14</maven.compiler.target> | ||
</properties> | ||
</project> |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_X"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
280 changes: 280 additions & 0 deletions
280
TSP-Optimization/src/main/java/prolab21/prolab/Arayuz.java
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,280 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package prolab21.prolab; | ||
|
||
/** | ||
* | ||
* @author harun | ||
*/ | ||
import java.awt.*; | ||
import java.awt.geom.Ellipse2D; | ||
import java.awt.geom.Line2D; | ||
import java.io.IOException; | ||
import java.util.*; | ||
import javax.swing.JFrame; | ||
import javax.swing.JPanel; | ||
import javax.swing.SwingUtilities; | ||
import java.util.List; | ||
|
||
|
||
@SuppressWarnings("serial") | ||
public class Arayuz extends JPanel { | ||
private static final int PREF_W = 1650; | ||
private static final int PREF_H = 750; | ||
private List<MyDrawable> drawables = new ArrayList<>(); | ||
|
||
|
||
public Arayuz() { | ||
setBackground(new Color(249,246,237)); | ||
} | ||
|
||
public void addMyDrawable(MyDrawable myDrawable) { | ||
drawables.add(myDrawable); | ||
repaint(); | ||
} | ||
|
||
|
||
@Override | ||
// make it bigger | ||
public Dimension getPreferredSize() { | ||
if (isPreferredSizeSet()) { | ||
return super.getPreferredSize(); | ||
} | ||
return new Dimension(PREF_W, PREF_H); | ||
} | ||
|
||
|
||
@Override | ||
protected void paintComponent(Graphics g) { | ||
|
||
|
||
super.paintComponent(g); | ||
Graphics2D g2 = (Graphics2D) g; | ||
Graphics2D g3 = (Graphics2D) g; | ||
g3.setStroke(new BasicStroke(4.0f)); | ||
g3.setPaint(new Color(255,16,71)); | ||
//g3.setPaint(new Color(255,0,54)); | ||
|
||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | ||
RenderingHints.VALUE_ANTIALIAS_ON); | ||
for (MyDrawable myDrawable : drawables) { | ||
myDrawable.draw(g2); | ||
} | ||
|
||
|
||
Koordinat isim = new Koordinat(); | ||
String[] dizi = new String[81]; | ||
Integer[][] Coordinat = new Integer[81][81]; | ||
try { | ||
Coordinat=isim.koordinat1(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
try { | ||
dizi=isim.SehirIsimleri(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
for (int i = 0; i < dizi.length; i++) { | ||
|
||
for (int j = 0; j < 1; j++) { | ||
|
||
g3.draw(new Ellipse2D.Double(Coordinat[i][0], Coordinat[i][1], 10, 10)); | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
for (int i=0; i<81; i++){ | ||
int fontSize=15; | ||
g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); | ||
|
||
g.setColor(new Color(74,69,64)); | ||
g.drawString( dizi[i], Coordinat[i][0]-20, Coordinat[i][1]-5); | ||
} | ||
|
||
|
||
} | ||
|
||
/*public void clearAll() { | ||
drawables.clear(); | ||
repaint(); | ||
}*/ | ||
|
||
|
||
private static void createAndShowGui( Integer[][] nums, List<ArrayList<Integer>> results, ArrayList<Integer> ugranacak ) { | ||
final List<MyDrawable> myDrawables = new ArrayList<>(); | ||
ArrayList<Integer> ugranacakSehirler; | ||
ugranacakSehirler=ugranacak; | ||
|
||
Collections.reverse(results); | ||
|
||
/*for (int j = 0; j < results.get(i).size(); j++) { | ||
myDrawables.add(new MyDrawable(new Line2D.Double( | ||
nums[results.get(i).get(j)][0], | ||
nums[results.get(i).get(j)][1], | ||
nums[results.get(i).get(j+1)][0], | ||
nums[results.get(i).get(j+1)][1]), | ||
Color.red, new BasicStroke(1))); | ||
}*/ | ||
int boyut=0; | ||
if (results.size() == 5) boyut=5; | ||
if (results.size()==2) boyut=2; | ||
if (results.size()==1) boyut=1; | ||
|
||
/*for (int i = 0; i < nums.length; i++) { | ||
for (int j = 0; j < 1; j++) { | ||
myDrawables.add(new MyDrawable(new RoundRectangle2D.Double(nums[i][0], nums[i][1], 10, 10,10,10), | ||
new Color(255, 0, 54), new BasicStroke(3))); | ||
} | ||
}*/ | ||
|
||
|
||
for (int i = 0; i < boyut; i++) { | ||
for (int j = 0; j < results.get(i).size()-2; j++) { | ||
if(i<boyut-1){ | ||
myDrawables.add(new MyDrawable(new Line2D.Double( | ||
nums[results.get(i).get(j)-1][0]+5, nums[results.get(i).get(j)-1][1]+6, nums[results.get(i).get(j+1)-1][0]+5, nums[results.get(i).get(j+1)-1][1]+6), | ||
new Color(0,0,0), new BasicStroke(4))); | ||
|
||
} | ||
|
||
if (i==boyut-1){ | ||
myDrawables.add(new MyDrawable(new Line2D.Double( | ||
nums[results.get(i).get(j)-1][0]+5, nums[results.get(i).get(j)-1][1]+6, nums[results.get(i).get(j+1)-1][0]+5, nums[results.get(i).get(j+1)-1][1]+6), | ||
new Color(0,155,255), new BasicStroke(4))); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
for (int i = 1; i<ugranacakSehirler.size(); i++){ | ||
myDrawables.add(new MyDrawable(new Ellipse2D.Double( | ||
nums[ugranacakSehirler.get(i)-1][0]+3, nums[ugranacakSehirler.get(i)-1][1]+3,5,5), | ||
new Color(255,255,0), new BasicStroke(17))); | ||
} | ||
|
||
for (int i = 0; i < boyut; i++) { | ||
for (int j = 0; j < results.get(i).size()-2; j++) { | ||
myDrawables.add(new MyDrawable(new Ellipse2D.Double( | ||
nums[results.get(i).get(j)-1][0]+3, nums[results.get(i).get(j)-1][1]+3, 5, 5), | ||
new Color(0,0,0), new BasicStroke(5))); | ||
if(j ==0){ | ||
myDrawables.add(new MyDrawable(new Ellipse2D.Double( | ||
nums[results.get(i).get(j)-1][0]+3, nums[results.get(i).get(j)-1][1]+3,5,5), | ||
new Color(124,252,0), new BasicStroke(17))); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
/*myDrawables.add(new MyDrawable(new Ellipse2D.Double(50, 10, 400, 400), | ||
Color.blue, new BasicStroke(18))); | ||
myDrawables.add(new MyDrawable(new Rectangle2D.Double(40, 200, 300, 300), | ||
Color.cyan, new BasicStroke(25))); | ||
myDrawables.add(new MyDrawable(new RoundRectangle2D.Double(75, 75, 490, 450, 40, 40), | ||
Color.green, new BasicStroke(12)));*/ | ||
|
||
|
||
|
||
final Arayuz drawChit = new Arayuz(); | ||
|
||
JFrame frame = new JFrame("YOL HARİTASI"); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.getContentPane().add(drawChit); | ||
frame.pack(); | ||
frame.setLocationRelativeTo(null); | ||
frame.setLocationByPlatform(true); | ||
frame.setResizable(false); | ||
frame.setVisible(true); | ||
|
||
for (MyDrawable myDrawable : myDrawables) { | ||
|
||
|
||
drawChit.addMyDrawable(myDrawable); | ||
|
||
|
||
} | ||
|
||
|
||
} | ||
|
||
public void Arayuz(List<ArrayList<Integer>> list, ArrayList<Integer> ugranacak) throws IOException { | ||
|
||
|
||
Koordinat koordinat = new Koordinat(); | ||
ArrayList<Integer> ugranacakSehirler; | ||
ugranacakSehirler=ugranacak; | ||
List<ArrayList<Integer>> gidisDonusArrayList; | ||
gidisDonusArrayList = list; | ||
Integer[][] matrix; | ||
matrix=koordinat.koordinat1(); | ||
Integer[][] finalMatrix = matrix; | ||
|
||
|
||
List<ArrayList<Integer>> finalGidisDonusArrayList = gidisDonusArrayList; | ||
|
||
|
||
ArrayList<Integer> finalUgranacakSehirler = ugranacakSehirler; | ||
SwingUtilities.invokeLater(() -> createAndShowGui(finalMatrix, finalGidisDonusArrayList, finalUgranacakSehirler)); | ||
|
||
|
||
|
||
|
||
|
||
} | ||
} | ||
|
||
class MyDrawable { | ||
private Shape shape; | ||
private Color color; | ||
private Stroke stroke; | ||
|
||
public MyDrawable(Shape shape, Color color, Stroke stroke) { | ||
this.shape = shape; | ||
this.color = color; | ||
this.stroke = stroke; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
public void draw(Graphics2D g2) { | ||
Color oldColor = g2.getColor(); | ||
Stroke oldStroke = g2.getStroke(); | ||
|
||
g2.setColor(color); | ||
g2.setStroke(stroke); | ||
g2.draw(shape); | ||
|
||
g2.setColor(oldColor); | ||
g2.setStroke(oldStroke); | ||
g2.setStroke(new BasicStroke(4.0f)); | ||
} | ||
|
||
|
||
} |
76 changes: 76 additions & 0 deletions
76
TSP-Optimization/src/main/java/prolab21/prolab/Koordinat.java
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,76 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package prolab21.prolab; | ||
|
||
/** | ||
* | ||
* @author harun | ||
*/ | ||
import java.io.*; | ||
import java.util.Scanner; | ||
|
||
|
||
class Koordinat { | ||
|
||
|
||
public Integer[][] koordinat1() throws FileNotFoundException, IOException { | ||
Integer[][] coordinatMatrix = new Integer[81][81]; | ||
//ArrayList<ArrayList<Integer>> coordinatArraylist = new ArrayList<ArrayList<Integer>>(); | ||
// ArrayList<Integer> clone = new ArrayList<Integer>(); | ||
|
||
File koordinat =new File("./src/sourceFiles/turkiye81.txt"); | ||
Scanner dosya = new Scanner(koordinat); | ||
|
||
for (int i = 0; i < 81; i++) { | ||
for (int j = 0; j < 1; j++) { | ||
int index = dosya.nextInt(); | ||
int xCoordinat=dosya.nextInt(); | ||
int yCoordinat= dosya.nextInt(); | ||
xCoordinat=(int)(xCoordinat/1.5); | ||
yCoordinat=(int)(yCoordinat/1.5); | ||
coordinatMatrix[i][j]=xCoordinat; | ||
coordinatMatrix[i][j+1]=yCoordinat; | ||
//System.out.println(coordinatMatrix[i][j]+ " "+ coordinatMatrix[i][j+1] ); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
return coordinatMatrix; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
public String[] SehirIsimleri() throws FileNotFoundException { | ||
String[] dizi = new String[81]; | ||
BufferedReader reader; | ||
try { | ||
reader = new BufferedReader(new FileReader( | ||
"./src/sourceFiles/turkiye81SehirIsımleri.txt")); | ||
int i=0; | ||
String line = reader.readLine(); | ||
while (line != null) { | ||
//System.out.println(line); | ||
// read next line | ||
dizi[i]=line; | ||
//System.out.println(dizi[i]); | ||
line = reader.readLine(); | ||
i++; | ||
} | ||
reader.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return dizi; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.