Skip to content

Commit 9300cfb

Browse files
committed
Source aima exemple i JAR
1 parent 4945b70 commit 9300cfb

File tree

367 files changed

+50878
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

367 files changed

+50878
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.class

AIMA.jar

1.5 MB
Binary file not shown.

lib/appframework-1.0.3.jar

258 KB
Binary file not shown.

lib/swing-layout-1.0.3.jar

115 KB
Binary file not shown.

lib/swing-worker-1.1.jar

10.7 KB
Binary file not shown.

srcaima/Demos/Chooser.form

+366
Large diffs are not rendered by default.

srcaima/Demos/Chooser.java

+460
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package IA.Centrals;
2+
3+
4+
import aima.search.framework.GoalTest;
5+
6+
public class CentralsEstatFinal implements GoalTest {
7+
8+
public boolean isGoalState(Object state) {
9+
return ((Representacio)(state)).isGoalState();
10+
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package IA.Centrals;
2+
3+
import aima.search.framework.HeuristicFunction;
4+
5+
public class CentralsFuncioHeuristica1 implements HeuristicFunction {
6+
7+
public boolean equals(Object obj) {
8+
boolean retValue;
9+
10+
retValue = super.equals(obj);
11+
return retValue;
12+
}
13+
14+
public double getHeuristicValue(Object state) {
15+
Representacio actual = (Representacio)state;
16+
int error = actual.getErrorTotal(1);
17+
//return(Integer.MAX_VALUE -error);
18+
return(error);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package IA.Centrals;
2+
3+
import aima.search.framework.HeuristicFunction;
4+
import java.util.Random;
5+
6+
public class CentralsFuncioHeuristica2 implements HeuristicFunction {
7+
8+
public boolean equals(Object obj) {
9+
boolean retValue;
10+
11+
retValue = super.equals(obj);
12+
return retValue;
13+
}
14+
15+
public double getHeuristicValue(Object state) {
16+
Representacio actual = (Representacio)state;
17+
//int error = actual.getErrorTotal(2);
18+
int error = actual.getErrorTotal(1);
19+
int rutil = actual.getRepetidorsUtil();
20+
int numr = actual.getNumRepetidors();
21+
22+
23+
//return(error+((error)/numr)*rutil);
24+
return (error/(numr-rutil+1));
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package IA.Centrals;
2+
3+
import aima.search.framework.HeuristicFunction;
4+
import java.util.Random;
5+
6+
public class CentralsFuncioHeuristica3 implements HeuristicFunction {
7+
double ponderacio;
8+
9+
public CentralsFuncioHeuristica3(int pond){
10+
11+
this.ponderacio=(double)pond;
12+
}
13+
14+
public boolean equals(Object obj) {
15+
boolean retValue;
16+
17+
retValue = super.equals(obj);
18+
return retValue;
19+
}
20+
21+
public double getHeuristicValue(Object state) {
22+
Representacio actual = (Representacio)state;
23+
double error = actual.getErrorTotal(1);
24+
double rutil = actual.getRepetidorsUtil();
25+
double numr = actual.getNumRepetidors();
26+
double errorMax = actual.getErrorMax();
27+
28+
double res = ((error/errorMax)*ponderacio)+((rutil/numr)*(100-ponderacio));
29+
res=res*100000;
30+
//System.out.println("res= "+res);
31+
return (int)res;
32+
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package IA.Centrals;
2+
3+
import aima.search.framework.HeuristicFunction;
4+
import java.util.Random;
5+
6+
public class CentralsFuncioHeuristica4 implements HeuristicFunction {
7+
double ponderacio;
8+
9+
10+
public boolean equals(Object obj) {
11+
boolean retValue;
12+
13+
retValue = super.equals(obj);
14+
return retValue;
15+
}
16+
17+
public double getHeuristicValue(Object state) {
18+
Representacio actual = (Representacio)state;
19+
20+
return actual.getErrorTotal(2);
21+
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
package IA.Centrals;
2+
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Vector;
7+
8+
import aima.search.framework.Successor;
9+
import aima.search.framework.SuccessorFunction;
10+
11+
public class CentralsGeneradorEstats implements SuccessorFunction {
12+
13+
private int debug;
14+
private int iter;
15+
private boolean[] vops;
16+
17+
public CentralsGeneradorEstats(int deb, boolean[] ops){
18+
this.debug = deb;
19+
iter=0;
20+
vops = new boolean[6];
21+
for(int i=0;i<6;i++)vops[i] = ops[i];
22+
}
23+
24+
public List getSuccessors(Object state) {
25+
26+
27+
28+
int count = 0;
29+
ArrayList retVal= new ArrayList();
30+
Representacio estat = (Representacio) state;
31+
32+
33+
// pintem la solucio escollida anteriorment
34+
/*cjf.setPlano(estat.getAmplada(),estat.getAltura(),estat.getPlano(),estat.getSol(),estat.getVNodo() );//3=tp
35+
cjf.repaint();
36+
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
37+
38+
39+
System.out.print("Ingrese string ");
40+
String r="";
41+
try {
42+
r = in.readLine();
43+
} catch (IOException e) {
44+
// TODO Auto-generated catch block
45+
e.printStackTrace();
46+
}
47+
System.out.println("string = "+r);
48+
*/
49+
if(debug>iter){
50+
iter++;
51+
52+
CentralsFuncioHeuristica1 CHF =new CentralsFuncioHeuristica1();
53+
Vector solActual = (Vector)estat.getSol();
54+
55+
56+
if(vops[0]){ //OPERADOR INTERCANVIAR CONNEXIO 1
57+
for(int i=0;i<solActual.size();i++){
58+
if(((Vector)solActual.get(i)).size()!=0) {
59+
for(int j=1; j<((Vector)solActual.get(i)).size();j++) {
60+
for (int k=0;k<solActual.size();k++) {
61+
if(((Vector)solActual.get(k)).size()!=0) {
62+
Representacio newEstat = new Representacio(estat);
63+
64+
if (newEstat.interConexio(i,Integer.parseInt(((Vector)solActual.get(i)).get(j).toString()),k)) {
65+
66+
//int v2=CHF.getHeuristicValue(newEstat);
67+
String S=new String("Interconexion= "+" "+i+" Up");
68+
retVal.add(new Successor(S,newEstat));
69+
count++;
70+
71+
}
72+
}
73+
74+
}
75+
}
76+
}
77+
}
78+
}
79+
if(vops[1]){ //OPEARDOR INTERCANVIAR CONNEXIO 2
80+
for(int i=0;i<solActual.size();i++){
81+
if(((Vector)solActual.get(i)).size()!=0) {
82+
for(int j=1; j<((Vector)solActual.get(i)).size();j++) {
83+
for (int k=0;k<solActual.size();k++) {
84+
if(((Vector)solActual.get(k)).size()!=0) {
85+
Representacio newEstat = new Representacio(estat);
86+
87+
if (newEstat.interConexio2(i,Integer.parseInt(((Vector)solActual.get(i)).get(j).toString()),k)) {
88+
89+
//int v2=CHF.getHeuristicValue(newEstat);
90+
String S=new String("Interconexion= "+" "+i+" Up");
91+
retVal.add(new Successor(S,newEstat));
92+
count++;
93+
94+
}
95+
}
96+
97+
}
98+
}
99+
}
100+
}
101+
}
102+
103+
//VARIABLES PER GESTIONAR OPERADORS DE REPETIDORS
104+
int numrep = estat.getNumRepetidors();
105+
boolean [] reputil= new boolean[numrep];
106+
107+
for(int i = 0;i< reputil.length;i++)reputil[i]=false;
108+
109+
110+
int rutil=0;
111+
for (int i=estat.getNumCentrals();i<estat.getEstat().size();i++) {
112+
if(((Vector)estat.getEstat().get(i)).size()!=0) {
113+
reputil[i-estat.getNumCentrals()]=true;
114+
rutil++;
115+
}
116+
}
117+
118+
if(vops[2]){ //OPEARDOR AFEGIR REPETIDOR
119+
if(rutil<estat.getMaxRep())
120+
{
121+
for(int i = estat.getNumCentrals();i<estat.getNumCentrals()+estat.getNumRepetidors();i++){
122+
if(!reputil[i-estat.getNumCentrals()]){
123+
for (int j=0;j<estat.getEstat().size();j++){
124+
if(((Vector)estat.getEstat().get(j)).size()!=0) {
125+
for (int k=1;k<((Vector)estat.getEstat().get(j)).size();k++) {
126+
int actual = Integer.parseInt(((Vector)estat.getEstat().get(j)).get(k).toString());
127+
if(actual>j){
128+
Representacio newEstat = new Representacio(estat);
129+
if(newEstat.afegirRepetidor(j,actual,i)){
130+
//int v2=CHF.getHeuristicValue(newEstat);
131+
String S=new String("AfegirRepetidor");
132+
retVal.add(new Successor(S,newEstat));
133+
count++;
134+
}
135+
136+
}
137+
}
138+
}
139+
}
140+
}
141+
}
142+
}
143+
}
144+
145+
if(vops[3]){ //OPEARDOR TREURE REP
146+
for(int i = estat.getNumCentrals();i<estat.getNumCentrals()+estat.getNumRepetidors();i++){
147+
if(reputil[i-estat.getNumCentrals()]){
148+
Representacio newEstat = new Representacio(estat);
149+
newEstat.treureRepetidor(i);
150+
//int v2=CHF.getHeuristicValue(newEstat);
151+
String S=new String("AfegirRepetidor");
152+
retVal.add(new Successor(S,newEstat));
153+
count++;
154+
155+
156+
}
157+
158+
}
159+
160+
}
161+
162+
163+
if(vops[4]){ //OPEARDOR INTERCANVIAR REPETIDOR
164+
for(int i = estat.getNumCentrals();i<estat.getNumCentrals()+estat.getNumRepetidors();i++){
165+
if(reputil[i-estat.getNumCentrals()]){
166+
for(int j = estat.getNumCentrals();j<estat.getNumCentrals()+estat.getNumRepetidors();j++){
167+
if(!reputil[j-estat.getNumCentrals()]){
168+
Representacio newEstat = new Representacio(estat);
169+
newEstat.interRepetidor(i,j);
170+
//int v2=CHF.getHeuristicValue(newEstat);
171+
String S=new String("InterRepetidor");
172+
retVal.add(new Successor(S,newEstat));
173+
count++;
174+
}
175+
}
176+
177+
}
178+
179+
}
180+
}
181+
182+
if(vops[5]){ //OPEARDOR INTERCANVIAR REPETIDOR 2
183+
int cvell = count;
184+
for(int i = estat.getNumCentrals();i<estat.getNumCentrals()+estat.getNumRepetidors();i++){
185+
if(reputil[i-estat.getNumCentrals()]){
186+
for(int j = i+1;j<estat.getNumCentrals()+estat.getNumRepetidors();j++){
187+
if(reputil[j-estat.getNumCentrals()]){
188+
Representacio newEstat = new Representacio(estat);
189+
if(newEstat.interRepetidor2(i,j)){
190+
//int v2=CHF.getHeuristicValue(newEstat);
191+
String S=new String("InterRepetidor");
192+
retVal.add(new Successor(S,newEstat));
193+
count++;
194+
}
195+
}
196+
197+
}
198+
199+
}
200+
201+
}
202+
System.out.println("cunt-cvell="+(count-cvell));
203+
}
204+
205+
206+
}//FI DEBUG ITER
207+
208+
System.out.println("num estats generats= " + count);
209+
return retVal;
210+
211+
}
212+
}

0 commit comments

Comments
 (0)