Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 biber;
- public class BiberSilo {
- private java.util.ArrayList<Biber> nodeList;
- public BiberSilo(int n) // Finde Leerlauflänge (LLL) für alle
- { // Konstellationen mit Gesamtzahl Biber n
- int maxLLL = 0;
- int maxA = 0, maxB = 0, maxC = 0;
- // Durchlaufe alle Konstellationen mit Bibermenge n.
- // i=Startzahl Silo A, j=Startzahl Silo B
- for(int i=1;i<n/2;i++)
- {
- for(int j=1;j<(n-i)/2;j++)
- {
- // Berechne LLL für aktuelle Konstellation
- int actLLL = BiberSolver(new Biber(i,j,(n-i-j),0));
- // Speichere Konstellation falls neues
- // maximales LLL gefunden
- if(actLLL>maxLLL)
- {
- maxLLL = actLLL;
- maxA = i;
- maxB = j;
- maxC = (n-i-j);
- }
- }
- }
- System.out.println("Schwierigste Konstellation ist ("+maxA+","+maxB+","+maxC+") mit einem LLL="+maxLLL);
- }
- public int BiberSolver(Biber Biber)
- {
- // Lege neue Listenstruktur an
- nodeList = new java.util.ArrayList<Biber>();
- // Füge die Startkonstellation hinzu
- nodeList.add(Biber);
- while(true)
- {
- // Entferne vordersten Knoten
- Biber actNode = nodeList.get(0);
- nodeList.remove(0);
- // Aktuelle Konstellation ist Lösung?
- if(actNode.isSolution())
- return actNode.n+1;
- // Führe die drei möglichen Züge durch und füge die
- // dadurch entstehenden Konstellationen der Liste hinzu
- nodeList.add(new Biber(actNode.a-actNode.b,actNode.b*2,actNode.c,actNode.n+1));
- nodeList.add(new Biber(actNode.a-actNode.c,actNode.b,actNode.c*2,actNode.n+1));
- nodeList.add(new Biber(actNode.a,actNode.b-actNode.c,actNode.c*2,actNode.n+1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement