-
Notifications
You must be signed in to change notification settings - Fork 49
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
JIMMY
authored and
JIMMY
committed
Apr 17, 2018
1 parent
fbf2e50
commit 7a41e69
Showing
12 changed files
with
80 additions
and
3 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 @@ | ||
/it/ |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Binary file modified
BIN
+0 Bytes
(100%)
VotiNobel/bin/it/polito/tdp/model/Esame.class
100755 → 100644
Binary file not shown.
Binary file modified
BIN
+1.77 KB
(380%)
VotiNobel/bin/it/polito/tdp/model/Model.class
100755 → 100644
Binary file not shown.
Binary file modified
BIN
+677 Bytes
(220%)
VotiNobel/bin/it/polito/tdp/model/TestModel.class
100755 → 100644
Binary file not shown.
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 |
---|---|---|
@@ -1,14 +1,84 @@ | ||
package it.polito.tdp.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import it.polito.tdp.dao.EsameDAO; | ||
|
||
public class Model { | ||
|
||
private List<Esame> esami; | ||
private EsameDAO edao; | ||
private List<Esame> soluzione; | ||
private double bestAvg; | ||
|
||
public Model() { | ||
edao = new EsameDAO(); | ||
esami = edao.getTuttiEsami(); | ||
// for (Esame e: esami) { | ||
// System.out.println(e); | ||
// } | ||
} | ||
|
||
public List<Esame> calcolaSottoinsiemeEsami(int numeroCrediti) { | ||
// inizializzazione | ||
soluzione = new ArrayList<Esame>(); | ||
bestAvg = 0.0; | ||
|
||
int step = 0; | ||
List<Esame> parziale = new ArrayList<>(); | ||
recursive(step, parziale, numeroCrediti); | ||
|
||
return soluzione; | ||
} | ||
|
||
public int totCrediti(List<Esame> parziale) { | ||
int somma = 0; | ||
for (Esame e: parziale) { | ||
somma += e.getCrediti(); | ||
} | ||
return somma; | ||
} | ||
|
||
public double avg(List<Esame> parziale) { | ||
double avg = 0; | ||
for (Esame e : parziale) { | ||
avg += e.getCrediti() * e.getVoto(); | ||
} | ||
avg /= totCrediti(parziale); | ||
return avg; | ||
} | ||
|
||
private void recursive(int step, List<Esame> parziale, int numeroCrediti) { | ||
|
||
// Debug ?? | ||
// for (Esame e : parziale) { | ||
// System.out.print(e.getCodins() + " "); | ||
// } | ||
// System.out.println(" "); | ||
|
||
|
||
// Condizione di terminazione | ||
if (totCrediti(parziale) > numeroCrediti) { | ||
return; | ||
} | ||
|
||
System.out.println("TODO!"); | ||
// Controllo se ho trovato una nuova soluzione migliore | ||
if (totCrediti(parziale) == numeroCrediti) { | ||
if (avg(parziale) > bestAvg) { | ||
soluzione = new ArrayList(parziale); | ||
bestAvg = avg(parziale); | ||
} | ||
} | ||
|
||
return null; | ||
// Generazione di una nuova soluzione parziale | ||
for (Esame esame : esami) { | ||
if (!parziale.contains(esame)) { | ||
parziale.add(esame); | ||
recursive(step+1, parziale, numeroCrediti); | ||
parziale.remove(esame); | ||
} | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package it.polito.tdp.model; | ||
|
||
import java.util.List; | ||
|
||
public class TestModel { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
|
||
Model model = new Model(); | ||
model.calcolaSottoinsiemeEsami(20); | ||
List<Esame> soluzione = model.calcolaSottoinsiemeEsami(22); | ||
|
||
System.out.println("Migliore combinazione di esami: "); | ||
for (Esame e : soluzione) { | ||
System.out.println(e); | ||
} | ||
} | ||
|
||
} |