I am about to generate a starting solution for a tabu search heuristic using multi-dimensional arrays. While that is fine as long as the program is up and running, as well as the computer, i would like to know, how exactly can i store the starting solution?
Let us say i got an array [10][10][10][10]. I let the program fill them with random numbers, due to a method. Now i want to "save" those values for later use. I shut down my computer for the day and would like to continue tomorrow. How would i have to do it? I don't know any code for that case. As i have to work with the chosen starting solution for several months, i cant simply let my PC run nonstop.
Any help appreciated, thanks :)
Edit: I got some code now, but i get an error: "outputFile cannot be resolved" I can not fix it so far. But i think it should work? I can not find any help on storing multidimensional arrays.
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.File;
public class speichern{
public static void main (String args[]) throws FileNotFoundException {
PrintWriter outputfile = new PrintWriter("test.txt");
int [][][]array = new int[10][10][10];
int i = 0;
int j = 0;
int k = 0;
int min = 50;
int max = 100;
//Generate random int value from 50 to 100
System.out.println("Random value in int from "+min+" to "+max+ ":");
for (i=0; i < 10; i++) {
for (j=0; j < 10; j++) {
for (k=0; k < 10; k++) {
//System.out.println("Test");
array[i][j][k] = (int)Math.floor(Math.random()*(max-min+1)+min);
outputFile.println(array[i][j][k]);
}
}
}
outputFile.close();
for (i=0; i < 10; i++) {
for (j=0; j < 10; j++) {
for (k=0; k < 10; k++) {
//System.out.println("Test");
System.out.print(array[i][j][k]+" ");
}
System.out.println("");
}
System.out.println("i ist "+i);
}
System.out.println(array[8][1][3]);
}
}