id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
237431ff-e861-4611-9470-e809a9a6b376 | public void cycle(long n) {
for (long i = 1; i <= n; i++){
result = result * i;
}
System.out.println(result);
//return result;
} |
96ea9c02-1cb0-4a13-b3d8-0a666a1f9600 | public long recursion(long n) {
if (n == 1){
return 1;
}
else result = recursion(n-1) * n;
//System.out.println(result+"\n");
return result;
} |
77f41a99-dae2-4a23-bea7-a2ec92dd5b75 | public BigInteger bigNumber(BigInteger n) {
if (n.equals(BigInteger.ONE)){
return BigInteger.ONE;
}
else resultBig = bigNumber(n.subtract(BigInteger.ONE)).multiply(n);
//System.out.println(resultBig.toString()+"\n");
return resultBig;
} |
b4c3257f-cdef-4571-8580-14188c711536 | public static void main(String[] args) {
LinkedList<Point> openList = new LinkedList<Point>();
LinkedList<Point> closedList = new LinkedList<Point>();
LinkedList<Point> tmpList = new LinkedList<Point>();
} |
dbd607c0-a3ed-43b6-bf14-53c119a529b4 | @Override
public void printShortestPath(Point[][] map, Point start, Point end) {
int leftX=start.getX()-1;
int upY=start.getY()+1;
int rightX=start.getX()+1;
int downY=start.getY()-1;
} |
1f4c6690-bd49-43a3-aac4-4dac84c23f60 | public void printShortestPath(Point[][] map, Point start, Point end); |
f2f617ec-200a-4fcc-9a8b-c948447656e7 | @Override
public int getX() {
return this.x;
} |
a1f3e4ed-023c-4e6d-9360-fa0d172828b3 | @Override
public int getY() {
return this.y;
} |
23693d61-a537-4335-8de4-3b665ad68242 | @Override
public Point getParent() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} |
a24d7ff2-e4e1-425b-adfd-171082d50769 | @Override
public void setParent(Point parent) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} |
8dc74ff8-c7c1-49c8-88bf-12c5eba3c908 | public PointT(int x, int y, boolean blocked) {
this.x = x;
this.y = y;
this.blocked = blocked;
} |
2ba08f7f-8179-4607-a1a3-26bf3834945e | public int mandist(PointT finish) {
return 10 * (Math.abs(this.x - finish.x) + Math.abs(this.x - finish.x));
} |
374044e6-7ec0-46f4-b7ba-2eded389d554 | public int price(PointT finish) {
if (this.x == finish.x || this.y == finish.y) {
return 10;
} else {
return 14;
}
} |
8c7ae68c-e0a4-4406-b75f-6839661d7fe4 | public void setAsStart() {
this.start = true;
} |
5accc72d-2976-4d7d-b796-e6ca99e82d4d | public void setAsFinish() {
this.finish = true;
} |
cbf5bf09-a5a8-4430-b9a5-5bf207213cf0 | public int getX(); |
e7125ee4-9472-4108-b005-3912f067578d | public int getY(); |
ece828c2-a3ed-4dd8-8a7b-e54cfd001c51 | public Point getParent(); |
768e826e-8601-4773-9e94-f0a1b9c29e90 | public void setParent(Point parent); |
99ea8f6c-981b-4d8e-98fb-a6fde78d5233 | private static int showMenu(){
System.out.println("\n1. Bubble sort.");
System.out.println("2. Merge sort.");
System.out.println("3. Count sort.");
System.out.println("4. Tree sort.");
System.out.println("0. Exit.");
int userChoice = sc.nextInt();
return userChoice;
} |
ae246c1d-8af1-473f-bf6f-10903b1b6835 | public static void main(String[] args) {
System.out.print("Enter the array's length\n");
int userNumber = sc.nextInt();
int[] array = new int[userNumber];
for (int i = 0; i < userNumber; i++){
array[i] = r.nextInt(100);
}
System.out.println(Arrays.toString(array)+"-before sorting\n");
int userChoice;
do {
userChoice = showMenu();
switch(userChoice){
case 1: MegaSorter sort1 = new MegaSorter(new BubbleSort());
sort1.setDelegate(new BubbleSort());
sort1.sort(array);
System.out.println("Bubble sort is completed");
System.out.println(Arrays.toString(array)+"-after sorting\n");
break;
case 2: MegaSorter sort2 = new MegaSorter(new MergeSort());
sort2.setDelegate(new MergeSort());
sort2.sort(array);
System.out.println("Merge sort is completed");
System.out.println(Arrays.toString(array)+"-after sorting\n");
break;
case 3: MegaSorter sort3 = new MegaSorter(new CountSort());
sort3.setDelegate(new CountSort());
sort3.sort(array);
System.out.println("Count sort is completed");
System.out.println(Arrays.toString(array)+"-after sorting\n");
break;
case 4: MegaSorter sort4 = new MegaSorter(new TreeSort());
sort4.setDelegate(new TreeSort());
sort4.sort(array);
System.out.println("Tree sort is completed");
System.out.println(Arrays.toString(array)+"-after sorting\n");
break;
default: break;
}
} while (userChoice != 0);
} |
0183f6b2-3cbf-4c2e-aa70-e25768278f86 | public void sort(int[] array); |
c03c862e-edab-4174-9955-c48f06817a90 | public void setDelegate(Sorter delegate) {
this.delegate = delegate;
} |
e2cc8572-1116-4996-91fa-38e221c68832 | public MegaSorter(Sorter delegate) {
this.delegate = delegate;
} |
b72d1ff2-9dcb-489a-aef7-00cd3269b2b7 | public void sort(int[] arr) {
delegate.sort(arr);
} |
bb9cbc4d-4f89-4a86-92d0-3e50c2cc92a8 | @Override
public void sort(int[] array) {
int i, j, b = 0;
int[] c = new int[100];
for (i = 0; i < 100; i++) c[i] = 0;
for (i = 0; i < array.length; i++) {
c[array[i]] = c[array[i]] + 1;
b = 0;
}
for (j = 0; j < 100; j++) {
for (i = 0; i < c[j]; i++) {
array[b] = j;
b = b + 1;
}
}
} |
4e346a1d-0d2a-4eb5-b185-6ce800ab0d49 | @Override
public void sort(int[] array) {
} |
7f683a67-9b22-4f00-ba42-a098715e17f6 | private void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
} |
e83e8f85-022f-4d98-b525-1eabe3a523cb | @Override
public void sort(int[] array) {
for( int i = array.length-1; i > 0; i--){
for (int j = 0; j < i; j++) {
if(array[j]>array[j+1]){
swap(array, j ,j+1);
}
}
}
} |
9eef8974-d995-4b21-9a1b-0e1667f4bd3d | @Override
public void sort(int[] array) {
if (array.length > 1) {
// split array into two halves
int[] left = leftHalf(array);
int[] right = rightHalf(array);
// recursively sort the two halves
sort(left);
sort(right);
// merge the sorted halves into a sorted whole
merge(array, left, right);
}
} |
841c72b0-03e9-4709-b04d-717ff5576629 | public static int[] leftHalf(int[] array) {
int size1 = array.length / 2;
int[] left = new int[size1];
for (int i = 0; i < size1; i++) {
left[i] = array[i];
}
return left;
} |
c2e1594f-1a80-4386-bb46-89afdb11fae7 | public static int[] rightHalf(int[] array) {
int size1 = array.length / 2;
int size2 = array.length - size1;
int[] right = new int[size2];
for (int i = 0; i < size2; i++) {
right[i] = array[i + size1];
}
return right;
} |
bc64d49a-7d0e-4ef4-89c0-db58506a3d35 | public static void merge(int[] result, int[] left, int[] right) {
int i1 = 0; // index into left array
int i2 = 0; // index into right array
for (int i = 0; i < result.length; i++) {
if (i2 >= right.length || (i1 < left.length &&
left[i1] <= right[i2])) {
result[i] = left[i1]; // take from left
i1++;
} else {
result[i] = right[i2]; // take from right
i2++;
}
}
} |
e0d823e9-106e-488a-9a0c-9a4b70eeabbe | private Normalise(final File theFile, NormaliseCLI cli) {
file = theFile;
tabSize = cli.getTabSize();
retainOddSpaces = cli.isKeepingOddSpaces();
retainBlankLines = !cli.isDiscardingBlankLines();
} |
15627497-71b7-4f96-9711-934dfee6a3e2 | private static void croak(final String s, final Exception e) {
e.printStackTrace();
System.err.println("Internal error: " + s + ": " + e.getMessage());
System.exit(1);
} |
9c5bf7b3-a43a-4dfd-abe0-ca8630fb32b0 | private CharArrayWriter process(final Reader in) throws IOException {
final CharArrayWriter w = new CharArrayWriter();
final WhitespaceNormaliser norm =
new WhitespaceNormaliser(retainOddSpaces, retainBlankLines, tabSize);
norm.process(in, w);
return w;
} |
0cbd6041-1ac0-41be-b711-2679291c68a7 | public void run() {
/*
* Open the input file and then process it.
*/
CharArrayWriter w;
try (InputStream is = new FileInputStream(file);
Reader in = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
/*
* Run through the input file processing each character in turn until we get to the end. The results are
* collected in a CharArrayWriter.
*/
w = process(in);
} catch (FileNotFoundException e) {
croak("input file not found", e);
return;
} catch (UnsupportedEncodingException e) {
croak("UTF-8 not supported", e);
return;
} catch (IOException e) {
croak("I/O exception while processing file", e);
return;
}
/*
* Write the processed data back into the same file.
*/
try (OutputStream os = new FileOutputStream(file);
Writer out = new OutputStreamWriter(os, "UTF-8")) {
w.writeTo(out);
} catch (FileNotFoundException e) {
croak("output file not found", e);
return;
} catch (UnsupportedEncodingException e) {
croak("UTF-8 not supported", e);
return;
} catch (IOException e) {
croak("I/O exception while writing output file", e);
return;
}
} |
be9f49a6-705a-40c4-a895-f0d94aa4672e | public static void main(final String[] args) {
final String progName = "Normalise";
final NormaliseCLI cli = new NormaliseCLI();
final JCommander jc = new JCommander(cli);
jc.setProgramName(progName);
try {
jc.parse(args);
} catch (ParameterException e) {
System.out.println(progName + ": " + e.getMessage());
System.out.println();
jc.usage();
System.exit(1);
}
/*
* Handle the "help" command.
*/
if (cli.isHelp()) {
jc.usage();
return;
}
/*
* Acquire name of file to process.
*/
List<String> files = cli.getParameters();
if (files.size() != 1) {
jc.usage();
System.exit(1);
}
Normalise norm = new Normalise(new File(files.get(0)), cli);
norm.run();
} |
f02d43d0-b409-4317-ab2d-740844274ffe | public List<String> getParameters() {
return parameters;
} |
39fd1436-0c93-4fdc-b1bb-6713c74b103c | public boolean isHelp() {
return help;
} |
91088c1b-299e-4340-b0be-ba2e24a4e3ee | public int getTabSize() {
return tabSize;
} |
04f451a6-f2e3-48f3-a1ad-40356097c525 | public boolean isDiscardingBlankLines() {
return discardingBlankLines;
} |
e925d8dd-c9fd-47f4-a3a0-9ec467d9a651 | public boolean isKeepingOddSpaces() {
return keepingOddSpaces;
} |
229c0f35-c409-476b-942b-2af2f2042005 | public void validate(String name, String value) {
try {
int n = Integer.parseInt(value);
if (n < 1 || n > 16) {
throw new ParameterException("Parameter " + name
+ " must be in the range 1 to 16 (found " + value + ")");
}
} catch (NumberFormatException e) {
throw new ParameterException("Parameter " + name
+ " must be an integer (found " + value + ")");
}
} |
6922ac82-5748-4aac-a272-65d5d04095f9 | public WhitespaceNormaliser(final boolean retainOddSpaces,
final boolean retainBlankLines, final int spacesPerTab) {
retainingOddSpaces = retainOddSpaces;
retainingBlankLines = retainBlankLines;
tabSize = spacesPerTab;
} |
a320e17b-caf4-4ed5-a524-6ab6f335afd3 | public void process(final Reader in, final Writer out) throws IOException {
// Checkstyle:CyclomaticComplexity|MethodLength ON
// amount of leading white space
int lead = 0;
// processing the start of the line
boolean start = true;
for (;;) {
final int c = in.read();
if (start) {
switch (c) {
case -1:
// end of input at line start
return;
case '\r':
// drop carriage return if we see one
break;
case ' ':
lead++;
break;
case '\t':
do {
lead++;
} while ((lead % tabSize) != 0);
break;
case '\n':
// line contains only whitespace
// throw away white space entirely
lead = 0;
if (retainingBlankLines) {
out.append('\n');
}
break;
default:
// flush leading space as tabs
while (lead >= tabSize) {
lead -= tabSize;
out.append('\t');
}
/*
* If the tabs don't make up the required space exactly, optionally make up the difference with
* spaces.
*/
if (retainingOddSpaces) {
while (lead > 0) {
lead--;
out.append(' ');
}
}
// no longer processing leading space
start = false;
// retain this character
out.append((char) c);
break;
}
} else {
switch (c) {
case -1:
// end of file in middle of line
out.append('\n');
return;
case '\n':
start = true;
lead = 0;
out.append((char) c);
break;
default:
out.append((char) c);
break;
}
}
}
} |
2e4db2be-a468-4d24-8c83-ff03b5ee4379 | private Reader acquireResource(String fileName) throws IOException {
final String resourceName = "/" + fileName;
final InputStream is = WhitespaceNormaliserTest.class.getResourceAsStream(resourceName);
if (is == null) {
throw new IOException("resource " + resourceName + " not found");
}
return new BufferedReader(new InputStreamReader(is, "UTF-8"));
} |
33444f22-cb3e-4cd4-9cff-b2388589aa40 | private String acquireString(String fileName) throws IOException {
final Reader in = acquireResource(fileName);
final StringBuilder sb = new StringBuilder();
for (;;) {
final int c = in.read();
if (c == -1) {
break;
}
sb.append((char)c);
}
in.close();
return sb.toString();
} |
d57747db-818d-4172-b38b-a0a2d32ba791 | @Test
public void standardOptions() throws IOException {
final Reader in = acquireResource("standardOptionsIn.txt");
final String expected = acquireString("standardOptionsOut.txt");
final Writer out = new StringWriter();
final WhitespaceNormaliser norm = new WhitespaceNormaliser(false, true, 4);
norm.process(in, out);
final String result = out.toString();
Assert.assertEquals(result, expected);
} |
eb47b139-ca88-46ed-95ba-0f389a04c6b8 | @Test
public void noBlankLines() throws IOException {
final Reader in = acquireResource("noBlankLinesIn.txt");
final String expected = acquireString("noBlankLinesOut.txt");
final Writer out = new StringWriter();
final WhitespaceNormaliser norm = new WhitespaceNormaliser(false, false, 4);
norm.process(in, out);
final String result = out.toString();
Assert.assertEquals(result, expected);
} |
c3cea678-b8dc-4f27-a398-5f24a09cfca3 | @Test
public void tabSize() throws IOException {
final Reader in = acquireResource("tabSizeIn.txt");
final String expected = acquireString("tabSizeOut.txt");
final Writer out = new StringWriter();
final WhitespaceNormaliser norm = new WhitespaceNormaliser(false, true, 3);
norm.process(in, out);
final String result = out.toString();
Assert.assertEquals(result, expected);
} |
1323a4ff-9575-4ea1-98c8-b312cdb24db9 | @Test
public void oddSpaces() throws IOException {
final Reader in = acquireResource("oddSpacesIn.txt");
final String expected = acquireString("oddSpacesOut.txt");
final Writer out = new StringWriter();
final WhitespaceNormaliser norm = new WhitespaceNormaliser(true, true, 4);
norm.process(in, out);
final String result = out.toString();
Assert.assertEquals(result, expected);
} |
17bfa268-559c-492c-b20a-ad3b32713e34 | private void expectException(String[] args) {
NormaliseCLI cli = new NormaliseCLI();
try {
new JCommander(cli, args);
} catch (ParameterException pe) {
// this is expected
return;
}
Assert.fail("expected a parameter exception");
} |
4d0e6cb6-e9c3-49bb-8220-b04880b6d0e9 | @Test
public void tabSize() {
NormaliseCLI cli = new NormaliseCLI();
new JCommander(cli, new String[]{"--tabSize=5"});
Assert.assertEquals(cli.getTabSize(), 5);
// test some bad values
expectException(new String[]{"--tabSize=bad"});
expectException(new String[]{"--tabSize=-1"});
expectException(new String[]{"--tabSize=0"});
expectException(new String[]{"--tabSize=99"});
} |
c313123f-c5ef-4cb7-9793-6e7f5e652d9d | public String getPaises() {
return paises;
} |
4a85edef-0e4e-43d5-b777-30c5915b521b | public void setPaises(String paises) {
this.paises = paises;
} |
a77c72d9-5163-40a9-89a7-6bc82b252df4 | public Paises() {
} |
f585dec8-fd12-4a35-a844-5cf6ca9c4d27 | public String Paises(){
String paises = "";
return paises;
} |
00934c10-c985-4056-8fef-193d2ae2d15d | public Paises(String paises) {
this.paises = paises;
} |
8c97fd53-8927-4636-8421-185081500fc7 | public static void main(String[] args) {
Controller c = new Controller();
Random r = new Random();
int num = r.nextInt(3);
if(num==0) {
for (int v=0; v<10; v++){
System.out.println(c.iniciarTimes());
}
}
else if (num==1) {
for (int v=0; v<10; v++){
System.out.println(c.iniciarBandas());
}
}
else {
for (int v=0; v<10; v++){
System.out.println(c.iniciarPaises());
}
}
} |
9ff64a6f-2a73-4b6c-b015-25778214c5bd | public String getBandas() {
return bandas;
} |
5d101c11-ba2a-40ae-8ef8-33af0b9dfc11 | public void setBandas(String bandas) {
this.bandas = bandas;
} |
8b6190bf-d6c1-45b3-a3c4-32301c09b727 | public Bandas(String bandas) {
this.bandas = bandas;
} |
17b9667f-8268-4bdf-89bb-8e150b731c76 | public String getTimes() {
return times;
} |
dbe53771-20ea-4ea3-a8a7-289b37057ed0 | public void setTimes(String times) {
this.times = times;
} |
d9af7f57-9745-4fdb-8a5f-d5198585d53c | public Times(String times) {
this.times = times;
} |
0dafccc2-252a-4385-a437-89d9986c4924 | public String iniciarTimes() {
//inicia objetos --- ja com os valores , nomes dos times
Times t0 = new Times("Sao Paulo");
Times t1 = new Times("Corinthians");
Times t2 = new Times("Palmeiras");
Times t3 = new Times("Santos");
Times t4 = new Times("Real Madrid");
Times t5 = new Times("Barcelona");
Times t6 = new Times("Manchester United");
Times t7 = new Times("Chelsea");
Times t8 = new Times("Ituano");
Times t9 = new Times("Atletico Sorocaba");
//cria um o bjeto que vai ser um vetor desse tipo
// e esse vetor do tipo Times ja vai conter os valores dos objetos acima criado
Times[] relacaoTimes = {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9};
Random r = new Random();
//essa string vai ter o valor do vetor acima referente a posicao que o numero aleatorio criar
String pega = relacaoTimes[r.nextInt(10)].getTimes() ;
//System.out.println("\n\n" + pega);
//retorna essa string, que sera um dos nomes dos times
return pega;
} |
586e0e20-5e4a-459d-82d3-430ed3c771fe | public String iniciarBandas() {
//inicia objetos --- ja com os valores , nomes dos times
Bandas t0 = new Bandas("Metallica");
Bandas t1 = new Bandas("Corinthians");
Bandas t2 = new Bandas("Palmeiras");
Bandas t3 = new Bandas("Santos");
Bandas t4 = new Bandas("Real Madrid");
Bandas t5 = new Bandas("Barcelona");
Bandas t6 = new Bandas("Manchester United");
Bandas t7 = new Bandas("Chelsea");
Bandas t8 = new Bandas("Ituano");
Bandas t9 = new Bandas("Atletico Sorocaba");
//cria um o bjeto que vai ser um vetor desse tipo
// e esse vetor do tipo Times ja vai conter os valores dos objetos acima criado
Bandas[] relacaoBandas = {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9};
Random r = new Random();
//essa string vai ter o valor do vetor acima referente a posicao que o numero aleatorio criar
String pega = relacaoBandas[r.nextInt(10)].getBandas() ;
//System.out.println("\n\n" + pega);
//retorna essa string, que sera um dos nomes dos times
return pega;
} |
974c29a4-2e19-46e6-ad81-9200fc1fac5b | public String iniciarPaises() {
//inicia objetos --- ja com os valores , nomes dos Paises
Paises t0 = new Paises("Brasil");
Paises t1 = new Paises("Corinthians");
Paises t2 = new Paises("Palmeiras");
Paises t3 = new Paises("Santos");
Paises t4 = new Paises("Real Madrid");
Paises t5 = new Paises("Barcelona");
Paises t6 = new Paises("Manchester United");
Paises t7 = new Paises("Chelsea");
Paises t8 = new Paises("Ituano");
Paises t9 = new Paises("Atletico Sorocaba");
//cria um o bjeto que vai ser um vetor desse tipo
// e esse vetor do tipo Paises ja vai conter os valores dos objetos acima criado
Paises[] relacaoPaises = {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9};
Random r = new Random();
//essa string vai ter o valor do vetor acima referente a posicao que o numero aleatorio criar
String pega = relacaoPaises[r.nextInt(10)].getPaises() ;
//System.out.println("\n\n" + pega);
//retorna essa string, que sera um dos nomes dos Paises
return pega;
} |
9786f93e-934e-4a59-938f-1e54329d98d7 | public ControlUI(DataStore ds) {
// initComponents(); // The GUI code, generated by NetBeans is not called
this.ds = ds;
initComponents();
setTitle("Styrsystem grupp 3");
} |
2b0f5680-3196-49f8-b636-ba846d51da1f | public void appendStatus(String text) {
jTextArea1.append(text + "\n");
jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
} |
e15fb333-7898-43e3-a0cb-4503782a73e3 | public void showStatus() {
jTextArea1.append("Nodes: " + ds.nodes + "\n");
jTextArea1.append("Arcs: " + ds.arcs + "\n");
jTextArea1.append("Shelves: " + ds.shelves + "\n");
// jTextArea1.append("\nGrupp 3\n");
} |
c80e3900-ba09-4234-b3d6-db01c2ceca79 | @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
fileChooser = new javax.swing.JFileChooser();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jScrollPane3 = new javax.swing.JScrollPane();
jTextArea3 = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();
jTextArea4 = new javax.swing.JTextArea();
jScrollPane5 = new javax.swing.JScrollPane();
jTextArea5 = new javax.swing.JTextArea();
jLabel2 = new javax.swing.JLabel();
fileChooser.setDialogTitle("Add file");
fileChooser.setFileFilter(MyCustomFilter);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(700, 350));
jPanel1 = new MapPanel(ds);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jPanel1.setPreferredSize(new java.awt.Dimension(700, 350));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 609, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 348, Short.MAX_VALUE)
);
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setBorder(javax.swing.BorderFactory.createTitledBorder("Meddelanden:"));
jScrollPane1.setViewportView(jTextArea1);
jButton1.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
jButton1.setText(" Start");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton3.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
jButton3.setText("Stopp");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jTextArea2.setEditable(false);
jTextArea2.setColumns(20);
jTextArea2.setForeground(new java.awt.Color(0, 0, 153));
jTextArea2.setLineWrap(true);
jTextArea2.setRows(5);
jTextArea2.setBorder(javax.swing.BorderFactory.createTitledBorder("Röd robot:"));
jScrollPane2.setViewportView(jTextArea2);
jTextArea3.setEditable(false);
jTextArea3.setBackground(java.awt.Color.gray);
jTextArea3.setColumns(20);
jTextArea3.setFont(new java.awt.Font("Ubuntu", 0, 24)); // NOI18N
jTextArea3.setForeground(java.awt.Color.red);
jTextArea3.setLineWrap(true);
jTextArea3.setRows(4);
jScrollPane3.setViewportView(jTextArea3);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Körs nu:");
jTextArea4.setEditable(false);
jTextArea4.setColumns(20);
jTextArea4.setForeground(new java.awt.Color(0, 0, 153));
jTextArea4.setLineWrap(true);
jTextArea4.setRows(5);
jTextArea4.setBorder(javax.swing.BorderFactory.createTitledBorder("Grön robot:"));
jScrollPane4.setViewportView(jTextArea4);
jTextArea4.getAccessibleContext().setAccessibleName("Grön robot:");
jTextArea5.setEditable(false);
jTextArea5.setBackground(java.awt.Color.gray);
jTextArea5.setColumns(20);
jTextArea5.setFont(new java.awt.Font("Ubuntu", 0, 24)); // NOI18N
jTextArea5.setForeground(java.awt.Color.green);
jTextArea5.setLineWrap(true);
jTextArea5.setRows(4);
jScrollPane5.setViewportView(jTextArea5);
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText("Körs nu:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE)))
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
.addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents |
0a8f13a0-3fa8-4055-a852-a4a2edd768c3 | public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
} |
fd8d459a-1251-41db-b913-d0264fa86c3e | public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
} |
9ce6dc5f-bce9-4bbf-9e06-d12d9244af21 | @Override
public boolean accept(File file) {
// Allow only directories, or files with ".txt" extension
return file.isDirectory() || file.getAbsolutePath().endsWith(".txt");
} |
9851fb2b-07ff-4bbe-accc-f696b7c8b594 | @Override
public String getDescription() {
// This description will be displayed in the dialog,
// hard-coded = ugly, should be done via I18N
return "Text documents (*.txt)";
} |
d2f0ecd9-184b-4686-9401-e38a0c678e76 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
jTextArea1.append("\nStarta optimeringen\n");
ds.start = true;
}//GEN-LAST:event_jButton1ActionPerformed |
e88379c8-81a7-4a1e-881d-a735081dbf28 | private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
jTextArea1.append("\nStopp men kör klart ordern först\n");
ds.start = false;
}//GEN-LAST:event_jButton3ActionPerformed |
24e1ace7-3dfe-4df0-85bf-093b233ce0a7 | public OptPlan(DataStore ds) {
this.ds = ds;
nodes = new ArrayList<Vertex>();
edges = new ArrayList<Edge>();
int diff;
for (int i = 0; i < ds.nodes; i++) {
Vertex lovation = new Vertex("" + (i + 1), "Nod #" + (i + 1));
//System.out.println("lovation.getId()" + lovation.getId());
nodes.add(lovation);
}
for (int i = 0; i < ds.arcs; i++) {
diff = (int) Math.max(Math.abs(ds.nodeY[ds.arcStart[i] - 1] - ds.nodeY[ds.arcEnd[i] - 1]), Math.abs(ds.nodeX[ds.arcStart[i] - 1] - ds.nodeX[ds.arcEnd[i] - 1]));
Edge lane = new Edge("" + (i + 1), nodes.get(ds.arcStart[i] - 1), nodes.get(ds.arcEnd[i] - 1), diff);
edges.add(lane);
//System.out.println("ds.arcStart[i] " + ds.arcStart[i]);
}
} |
a8fd7286-be61-4dc6-81ee-3d4315e7e9bd | public LinkedList<Vertex> createPlan(int start, int stop, int color, boolean intekrock) {
LinkedList<Vertex> path;
Graph graph = new Graph(nodes, edges);
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(graph, ds);
// Compute shortest path
dijkstra.execute(nodes.get(start - 1));
path = dijkstra.getPath(nodes.get(stop - 1));
//System.out.println("nodes.get(start) " + nodes.get(start-1));
//System.out.println("nodes.get(stop) " + nodes.get(stop-1));
Arrays.fill(ds.notoknumber, 0);
// Get shortest path
if (intekrock) {
System.out.println("path.size() " + path.size());
for (int i = 1; i < path.size() - 1; i++) {
ds.notoknumber[i] = Integer.parseInt(path.get(i).getId());
System.out.println("ds.notoknumber[i] " + ds.notoknumber[i]);
}
}
// Arcs in the shortest path
for (int i = 0; i < path.size() - 1; i++) {
for (int j = 0; j < ds.arcs; j++) {
if (ds.arcStart[j] == Integer.parseInt(path.get(i).getId())
&& ds.arcEnd[j]
== Integer.parseInt(path.get(i + 1).getId())) {
//System.out.println("Arc: " + j);
ds.arcColor[j] = color;
}
}
}
return path;
} |
a121126b-7cee-4e6a-bc79-feab47ad7106 | MapPanel(DataStore ds) {
this.ds = ds;
} |
71afcab2-2d4e-431a-a6b5-6a5cea227522 | protected void paintComponent(Graphics g) {
super.paintComponent(g);
final Color LIGHT_COLOR = new Color(150, 150, 150);
final Color DARK_COLOR = new Color(0, 0, 0);
final Color RED_COLOR = new Color(255, 0, 0);
final Color BLUE_COLOR = new Color(0, 0, 200);
final Color GREEN_COLOR = new Color(0, 255, 0);
int x, y;
int x1, y1;
int x2, y2;
final int circlesize = 10;
final int ysize = 350;
final int xsize = 700;
if (ds.networkRead == true) { // Only try to plot if data has been properly read from file
// Compute scale factor in order to keep the map in proportion when the window is resized
int height = getHeight();
int width = getWidth();
double xscale = 1.0 * width / xsize;
double yscale = 1.0 * height / ysize;
g.setColor(DARK_COLOR);
// Draw nodes as circles
for (int i = 0; i < ds.nodes; i++) {
x = (int) (ds.nodeX[i] * xscale);
y = (int) (ds.nodeY[i] * yscale);
if (i == 13) {
g.setColor(RED_COLOR);
} else {
g.setColor(DARK_COLOR);
}
g.fillOval(x - (circlesize / 2), height - y - circlesize / 2, circlesize, circlesize);
}
// Draw arcs
for (int i = 0; i < ds.arcs; i++) {
x1 = (int) (ds.nodeX[ds.arcStart[i] - 1] * xscale);
y1 = (int) (ds.nodeY[ds.arcStart[i] - 1] * yscale);
x2 = (int) (ds.nodeX[ds.arcEnd[i] - 1] * xscale);
y2 = (int) (ds.nodeY[ds.arcEnd[i] - 1] * yscale);
if (x1 == x2 && y1 < y2) {
x1 = x1 + 3;
x2 = x2 + 3;
} else {
x1 = x1 - 3;
x2 = x2 - 3;
}
if (y1 == y2 && x1 < x2) {
y1 = y1 - 3;
y2 = y2 - 3;
} else {
y1 = y1 + 3;
y2 = y2 + 3;
}
if (ds.arcColor[i] == 1) {
g.setColor(RED_COLOR);
} else if (ds.arcColor[i] == 2) {
g.setColor(GREEN_COLOR);
} else if (ds.arcColor[i] == 0) {
g.setColor(BLUE_COLOR);
}
g.drawLine(x1, height - y1, x2, height - y2);
}
x = (int) (ds.robot1X * xscale);
y = (int) (ds.robot1Y * yscale);
g.drawOval(x - ((circlesize + 10) / 2), height - y - (circlesize + 10) / 2, circlesize + 10, circlesize + 10);
x = (int) (ds.robot2X * xscale);
y = (int) (ds.robot2Y * yscale);
g.drawOval(x - ((circlesize + 10) / 2), height - y - (circlesize + 10) / 2, circlesize + 10, circlesize + 10);
}
} // end paintComponent |
2ca62beb-395e-4faf-9c2f-b69d747c40a3 | public GuiUpdate(DataStore ds, ControlUI cui) {
this.cui = cui;
this.ds = ds;
sleepTime = generator.nextInt(20000);
} |
d6620405-093b-4805-b4d8-4ad0774c68a8 | @Override
public void run() {
try {
while(!ds.updateUIflag){
Thread.sleep(100);
}
cui.appendStatus("GuiUpdate startar och kommer att köra i "
+ sleepTime + " millisekunder.");
int i = 1;
while (i <= 20) {
Thread.sleep(sleepTime / 20);
cui.appendStatus("Jag är tråd GuiUpdate! För " + i + ":te gången.");
ds.robot1X = ds.robot1X + 10; //blir ds.robotX = ds.nodeX[slutnoden när roboten har sagt att den är klar] - 1 nodeX[GPS[GPS.length-1]]
cui.repaint();
i++;
}
} catch (InterruptedException exception) {
}
cui.appendStatus("GuiUpdate är nu klar!");
} |
02465d5f-d9e7-40fa-be63-42938fe50726 | public Edge(String id, Vertex source, Vertex destination, int weight) {
this.id = id;
this.source = source;
this.destination = destination;
this.weight = weight;
} |
2ce0082b-f624-452e-84c5-8e65a551864a | public String getId() {
return id;
} |
7d3b7a4a-252b-4268-806d-2f135fd008b5 | public Vertex getDestination() {
return destination;
} |
1d819d4f-367c-4755-b16e-38305257b89c | public Vertex getSource() {
return source;
} |
f310d910-c384-4f45-a54c-aa9900a315ed | public int getWeight() {
return weight;
} |
363b0310-2c09-403d-aaa5-9c44c187e756 | @Override
public String toString() {
return source + " " + destination;
} |
f8096cda-bbae-4118-b669-84b4b1e8bd79 | public DataStore() {
// Initialize the datastore with fixed size arrays for storing the network data
nodes = 0;
arcs = 0;
shelves = 0;
nodeX = new double[99];
nodeY = new double[99];
arcStart = new int[1000];
arcEnd = new int[1000];
/*
* TO DO: Add data storage for the shelf data
*/
networkRead = false;
orders = 0;
orderStart = new int[99];
orderEnd = new int[99];
ordersRead = false;
} |
c34f56f7-73d5-4452-ae0f-651a1c9df70b | public void setFileName(String newFileName) {
this.fileName = newFileName;
} |
149a9572-44a3-4cca-b657-dc35ef8d568e | public String getFileName() {
return fileName;
} |
ba939bec-03a0-44bd-8a36-6587ec5becdb | public void readNet() {
final Color BLUE_COLOR = new Color(0, 0, 200);
String line;
if (fileName == null) {
System.err.println("No file name set. Data read aborted.");
return;
}
try {
File file = new File(fileName);
Scanner scanner = new Scanner(file, "iso-8859-1");
String[] sline;
// Read number of nodes
line = (scanner.nextLine());
nodes = Integer.parseInt(line.trim());
line = scanner.nextLine();
arcs = Integer.parseInt(line.trim());
line = scanner.nextLine();
shelves = Integer.parseInt(line.trim());
// Debug printout: network size data
System.out.println("Nodes: " + nodes);
System.out.println("Arcs: " + arcs);
System.out.println("Shelves: " + shelves);
// Read nodes as number, x, y
for (int i = 0; i < nodes; i++) {
line = scanner.nextLine();
//split space separated data on line
sline = line.split(" ");
nodeX[i] = Double.parseDouble(sline[1].trim());
nodeY[i] = Double.parseDouble(sline[2].trim());
}
// Debug printout: print data for node 1
System.out.println("Node 1: " + nodeX[0] + " " + nodeY[0]);
// Read arc list as start node number, end node number
for (int i = 0; i < arcs; i++) {
line = scanner.nextLine();
//split space separated data on line
sline = line.split(" ");
arcStart[i] = Integer.parseInt(sline[0].trim());
arcEnd[i] = Integer.parseInt(sline[1].trim());
}
for (int i = 0; i < shelves; i++) {
line = scanner.nextLine();
//split space separated data on line
sline = line.split(" ");
if ("A".equals(sline[0].trim())) {
shelfNumber[i] = 0; // Let the A shelf be represented by 0
} else {
shelfNumber[i] = Integer.parseInt(sline[0].trim());
}
shelfNode[i] = Integer.parseInt(sline[1].trim());
shelfDirection[i] = sline[2].trim();
}
// Debug printout: print data for the first shelf
System.out.println("Shelf 1: " + shelfNumber[0] + " " + shelfNode[0] + " " + shelfDirection[0]);
networkRead = true; // Indicate that all network data is in place in the DataStore
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
522218b9-0d35-452b-ac3b-ef4936c35be9 | public void readOrders() {
String line;
if (fileName == null) {
System.err.println("No file name set for order list. Data read aborted.");
return;
}
try {
File file = new File(fileName);
Scanner scanner = new Scanner(file, "iso-8859-1");
String[] sline;
// Read number of orders
line = (scanner.nextLine());
orders = Integer.parseInt(line.trim());
// Debug printout: network size data
System.out.println("Orders: " + orders);
// Read nodes as number, x, y
for (int i = 0; i < orders; i++) {
line = scanner.nextLine();
//split space separated data on line
sline = line.split(" ");
if ("A".equals(sline[0].trim())) {
orderStart[i] = 0; // Let the A shelf be represented by 0
} else {
orderStart[i] = Integer.parseInt(sline[0].trim());
}
if ("A".equals(sline[1].trim())) {
orderEnd[i] = 0;
} else {
orderEnd[i] = Integer.parseInt(sline[1].trim());
}
}
// Debug printout: print data for node 1
System.out.println("Order 1: " + orderStart[0] + " " + orderEnd[0]);
ordersRead = true; // Indicate that all network data is in place in the DataStore
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
b135f28a-79f3-462d-bbd4-7038298d82c1 | public Vertex(String id, String name) {
this.id = id;
this.name = name;
} |
c1d8f4fc-4ee9-4062-bc1e-ad1eb4b3569c | public String getId() {
return id;
} |
5eab19e7-10f3-4a05-a21e-3ca39a69233e | public String getName() {
return name;
} |
84e6ab63-bc9a-44fc-907c-4eb93581eeed | @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.