World building to max 6 elements

This commit is contained in:
L3o15 2025-05-12 19:16:28 +02:00
parent 8fe0d0e323
commit 3f77488b69
3 changed files with 25 additions and 29 deletions

View file

@ -34,7 +34,7 @@ public class LinearSystem {
while (tries-- > 0) {
int[] lambdaValues = new int[indipendentVariables];
for (int i = 0; i < indipendentVariables; i++) {
lambdaValues[i] = (rand.nextInt(n) + 1); // valori tra 1 e 9
lambdaValues[i] = (rand.nextInt(m) + 1); // valori tra 1 e 9
}
solutions = constructSolution(extendedMatrix, lambdaValues, rank);
@ -45,14 +45,10 @@ public class LinearSystem {
}
private boolean validNumbers(int[] x) {
boolean positive = false;
boolean negative = false;
for (int xi : x) {
if (xi > 0) positive = true;
else if (xi < 0) negative = true;
if (xi == 0) return false;
if (xi <= 0) return false;
}
return positive && negative;
return true;
}
private int[] constructSolution(int[][] extendedMatrix, int[] parameters, int rank) {

View file

@ -8,7 +8,7 @@ public class WorldBuilder {
Random rand = new Random();
// da cambiare il numero a 8
//int numElements = 3 + rand.nextInt(8);
int numElements = 5;
int numElements = 6;
List<Element> selectedElements = new ArrayList<>(Arrays.asList(allElements));
Collections.shuffle(selectedElements);
selectedElements = selectedElements.subList(0, numElements);
@ -23,7 +23,7 @@ public class WorldBuilder {
if (el == followingElement) {
links.put(el, 1);
} else if (el != element) {
links.put(el, 1);
links.put(el, 0);
}
}
@ -37,24 +37,24 @@ public class WorldBuilder {
continue;
}
// // controllo anche prima per evitare che magari da un estrazione si vada a togliere
// if (elementLinks.get(el) == 1){
// linkDirections.get(el).put(element, -1);
// }
//
// if (elementLinks.get(el) == 0) {
// if (Math.random() < 0.5) {
// linkDirections.get(el).put(element, 1);
// } else {
// linkDirections.get(el).put(element, -1);
// }
// }
//
// if (elementLinks.get(el) == 1){
// linkDirections.get(el).put(element, -1);
// } else {
// linkDirections.get(el).put(element, 1);
// }
// controllo anche prima per evitare che magari da un estrazione si vada a togliere
if (elementLinks.get(el) == 1){
linkDirections.get(el).put(element, -1);
}
if (elementLinks.get(el) == 0) {
if (Math.random() < 0.5) {
linkDirections.get(el).put(element, 1);
} else {
linkDirections.get(el).put(element, -1);
}
}
if (elementLinks.get(el) == 1){
linkDirections.get(el).put(element, -1);
} else {
linkDirections.get(el).put(element, 1);
}
}
}
@ -114,8 +114,8 @@ public class WorldBuilder {
if (el == element) {
continue;
}
//int direction = linkDirections.get(element).get(el);
graphElement.addLink(new ElementLink(solution[getIndex(element, el, pairIndex)], el));
int direction = linkDirections.get(element).get(el);
graphElement.addLink(new ElementLink(solution[getIndex(element, el, pairIndex)] * direction, el));
}
world.addElement(graphElement);
}