Skip to content
Snippets Groups Projects
Commit e72a96ff authored by Hugo Roussel's avatar Hugo Roussel
Browse files

Changed LocalModel's getMax to getMaxWithConstraint

parent c4985f2e
Branches
No related tags found
2 merge requests!3Merge masters,!2Merge dev into develop
...@@ -37,11 +37,11 @@ public interface LocalModel { ...@@ -37,11 +37,11 @@ public interface LocalModel {
public double getMaxProposition(); public double getMaxProposition();
/** /**
* Return the point (percept value) that produce the max proposition * Return the point (percept value) that produce the max proposition, considering some percepts are fixed.
* @return a HashMap with percept names as key, and their corresponding value. The oracle is the max proposition * @return a HashMap with percept names as key, and their corresponding value. The oracle is the max proposition
* @see LocalModel#getMaxProposition(Context) * @see LocalModel#getMaxProposition(Context)
*/ */
public HashMap<String, Double> getMax(); public HashMap<String, Double> getMaxWithConstraint(HashMap<String, Double> fixedPercepts);;
/** /**
* Gets the proposition with the lowest value possible * Gets the proposition with the lowest value possible
......
...@@ -128,7 +128,8 @@ public class LocalModelMillerRegression implements LocalModel{ ...@@ -128,7 +128,8 @@ public class LocalModelMillerRegression implements LocalModel{
ArrayList<Percept> percepts = context.getAmas().getPercepts(); ArrayList<Percept> percepts = context.getAmas().getPercepts();
double result = coefs[0]; double result = coefs[0];
if (coefs[0] == Double.NaN) System.exit(0); if (coefs[0] == Double.NaN)
throw new ArithmeticException("First coeficient of model cannot be NaN");
for (int i = 1 ; i < coefs.length ; i++) { for (int i = 1 ; i < coefs.length ; i++) {
...@@ -145,7 +146,7 @@ public class LocalModelMillerRegression implements LocalModel{ ...@@ -145,7 +146,7 @@ public class LocalModelMillerRegression implements LocalModel{
} }
@Override @Override
public HashMap<String, Double> getMax(){ public HashMap<String, Double> getMaxWithConstraint(HashMap<String, Double> fixedPercepts){
ArrayList<Percept> percepts = context.getAmas().getPercepts(); ArrayList<Percept> percepts = context.getAmas().getPercepts();
HashMap<String, Double> result = new HashMap<String, Double>(); HashMap<String, Double> result = new HashMap<String, Double>();
...@@ -157,20 +158,23 @@ public class LocalModelMillerRegression implements LocalModel{ ...@@ -157,20 +158,23 @@ public class LocalModelMillerRegression implements LocalModel{
for (int i = 1 ; i < coefs.length ; i++) { for (int i = 1 ; i < coefs.length ; i++) {
if (Double.isNaN(coefs[i])) coefs[i] = 0.0; if (Double.isNaN(coefs[i])) coefs[i] = 0.0;
if(coefs[i]>0) { double pos;
Percept p = percepts.get(i-1); Percept p = percepts.get(i-1);
double value = coefs[i] * context.getRanges().get(p).getEnd(); if(fixedPercepts.containsKey(p.getName())) {
result.put("oracle", value); pos = fixedPercepts.get(p.getName());
result.put(p.getName(), context.getRanges().get(p).getEnd()); } else {
} if(coefs[i]>0) {
else { pos = context.getRanges().get(p).getEnd();
Percept p = percepts.get(i-1); }
double value = coefs[i] * context.getRanges().get(p).getStart(); else {
result.put("oracle", value); pos = context.getRanges().get(p).getStart();
result.put(p.getName(), context.getRanges().get(p).getStart()); }
} }
double value = coefs[i] * pos;
result.put("oracle", result.get("oracle") + value);
result.put(p.getName(), pos);
} }
return result; return result;
} }
......
...@@ -431,7 +431,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA { ...@@ -431,7 +431,7 @@ public class AMOEBA extends Amas<World> implements IAMOEBA {
ArrayList<HashMap<String, Double>> sol = new ArrayList<>(); ArrayList<HashMap<String, Double>> sol = new ArrayList<>();
for(Context c : pac) { for(Context c : pac) {
sol.add(c.getLocalModel().getMax()); sol.add(c.getLocalModel().getMaxWithConstraint(known));
} }
HashMap<String, Double> max = new HashMap<>(); HashMap<String, Double> max = new HashMap<>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment