Commit 1473d2ff authored by Marc Schiller's avatar Marc Schiller
Browse files

Added other models and fixed a bug in addModel().

parent bf518b5b
......@@ -67,11 +67,7 @@ public class ModelBasedSegmentDatabase
// There is already this Type
if (models.get(type).containsKey(segmentID)) {
// There is already this SegID
if (models.get(type).get(segmentID).containsKey(dir)
|| (dir.equals(Direction.BOTH) && (models.get(type)
.get(segmentID).containsKey(Direction.UPLOAD)
|| models.get(type).get(segmentID)
.containsKey(Direction.DOWNLOAD)))) {
if (models.get(type).get(segmentID).containsKey(dir) || (models.get(type).get(segmentID).containsKey(Direction.BOTH) && (dir.equals(Direction.DOWNLOAD) || dir.equals(Direction.UPLOAD)))|| (dir.equals(Direction.BOTH) && (models.get(type).get(segmentID).containsKey(Direction.DOWNLOAD) || models.get(type).get(segmentID).containsKey(Direction.UPLOAD)))) {
// There is already a model defined
throw new ConfigurationException(
"Conflicting Models for SegmentID " + segmentID
......@@ -102,6 +98,8 @@ public class ModelBasedSegmentDatabase
models.put(type, tmp2);
}
System.out.println(models.toString());
}
AbstractModel getModel(int segID, ParameterType type, Boolean isUpload) {
......@@ -171,9 +169,10 @@ public class ModelBasedSegmentDatabase
if (!isAvailable) {
return 1;
}
return getModel(new Integer(getSegmentID()), ParameterType.DROPRATE, isUpload)
.getDouble(this.hostsInSegment.size());
// TODO: Eval other parameters first
return getModel(new Integer(getSegmentID()), ParameterType.DROPRATE,
isUpload).getDouble(this.hostsInSegment.size());
}
@Override
......@@ -182,8 +181,9 @@ public class ModelBasedSegmentDatabase
return 9999 * Time.MILLISECOND;
}
return getModel(new Integer(getSegmentID()), ParameterType.LATENCY, isUpload)
.getLong(this.hostsInSegment.size());
// TODO: Eval other parameters first
return getModel(new Integer(getSegmentID()), ParameterType.LATENCY,
isUpload).getLong(this.hostsInSegment.size());
}
@Override
......@@ -192,8 +192,10 @@ public class ModelBasedSegmentDatabase
return 0;
}
return getModel(new Integer(getSegmentID()), ParameterType.BANDWIDTH, isUpload)
.getLong(this.hostsInSegment.size());
// TODO: Eval other parameters first
return getModel(new Integer(getSegmentID()),
ParameterType.BANDWIDTH, isUpload)
.getLong(this.hostsInSegment.size());
}
@Override
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.views.fiveg.models;
public class CutOffModel extends AbstractModel {
private long a = 1;
private long b = 0;
private long c = 1;
private long d = 0;
public void setA(long a) {
this.a = a;
}
public void setB(long b) {
this.b = b;
}
public void setC(long c) {
this.c = c;
}
public void setD(long d) {
this.d = d;
}
private long heaviside(long x) {
if(x < 0) {
return 0;
} else {
return 1;
}
}
@Override
public long getLong(int users) {
return (long) getDouble(users);
}
@Override
public double getDouble(int users) {
return this.a * heaviside(this.c * users + this.d) + this.b;
}
@Override
public String toString() {
return "CutOffModel: cut(u) = " + this.a + " * θ(" + this.c + " * u + " + this.d + ") + " + this.b;
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.views.fiveg.models;
public class ExponentialModel extends AbstractModel {
// exp(u) = a * e ^(c * u + d) + b
private long a = 1;
private long b = 0;
private long c = 1;
private long d = 0;
public void setA(long a) {
this.a = a;
}
public void setB(long b) {
this.b = b;
}
public void setC(long c) {
this.c = c;
}
public void setD(long d) {
this.d = d;
}
@Override
public long getLong(int users) {
return (long) getDouble(users);
}
@Override
public double getDouble(int users) {
return this.a * Math.exp(this.c * users + this.d) + this.b;
}
@Override
public String toString() {
return "Exponential Model: exp(u) = " + this.a + " * e^(" + this.c + " * u + " + this.d + ") + " + this.b;
}
}
......@@ -42,5 +42,9 @@ public class LinearModel extends AbstractModel {
public double getDouble(int users) {
return (double) this.a * users + this.b;
}
public String toString() {
return "Linear Model: f(u) = " + a + " * u + " + b;
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.views.fiveg.models;
public class LogarithmicModel extends AbstractModel {
// log(u) = a * ln(c * u + d) + b
private long a = 1;
private long b = 0;
private long c = 1;
private long d = 0;
public void setA(long a) {
this.a = a;
}
public void setB(long b) {
this.b = b;
}
public void setC(long c) {
this.c = c;
}
public void setD(long d) {
this.d = d;
}
@Override
public long getLong(int users) {
return (long) getDouble(users);
}
@Override
public double getDouble(int users) {
return this.a * Math.log(this.c * users + this.d) + this.b;
}
@Override
public String toString() {
return "Logarithmic Model: log(u) = " + this.a + " * ln(" + this.c + " * u + " + this.d + ") + " + this.b;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment