summaryrefslogtreecommitdiff
path: root/opendc-compute/opendc-compute-topology
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-compute/opendc-compute-topology')
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt23
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt12
2 files changed, 17 insertions, 18 deletions
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
index a20bc2c2..cc2c4b4e 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
@@ -44,10 +44,10 @@ import java.io.InputStream
private val reader = TopologyReader()
// Lists used to make sure all cluster, host, power source and battery have unique names
-private val clusterNames: ArrayList<String> = ArrayList()
-private val hostNames: ArrayList<String> = ArrayList()
-private val powerSourceNames: ArrayList<String> = ArrayList()
-private val batteryNames: ArrayList<String> = ArrayList()
+private val clusterNames: HashMap<String, Int> = HashMap()
+private val hostNames: HashMap<String, Int> = HashMap()
+private val powerSourceNames: HashMap<String, Int> = HashMap()
+private val batteryNames: HashMap<String, Int> = HashMap()
/**
* Create a unique name for the specified [name] that is not already in the [names] list.
@@ -57,20 +57,19 @@ private val batteryNames: ArrayList<String> = ArrayList()
*/
private fun createUniqueName(
name: String,
- names: ArrayList<String>,
+ names: MutableMap<String, Int>,
): String {
if (name !in names) {
- names.add(name)
+ names[name] = 0
return name
}
- var i = 0
- var newName = "$name-$i"
- while (newName in names) {
- newName = "$name-${++i}"
- }
+ val latestValue = names[name]
+
+ val newName = "$name-$latestValue"
+
+ names[name] = latestValue!! + 1
- names.add(newName)
return newName
}
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
index 3d8b63dc..920d8373 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
@@ -34,7 +34,7 @@ import org.opendc.simulator.compute.power.batteries.policy.DoubleThresholdBatter
import org.opendc.simulator.compute.power.batteries.policy.RunningMeanBatteryPolicy
import org.opendc.simulator.compute.power.batteries.policy.RunningMeanPlusBatteryPolicy
import org.opendc.simulator.compute.power.batteries.policy.SingleThresholdBatteryPolicy
-import org.opendc.simulator.engine.graph.FlowGraph
+import org.opendc.simulator.engine.engine.FlowEngine
/**
* Definition of a Topology modeled in the simulation.
@@ -236,21 +236,21 @@ public data class RunningQuartilesPolicyJSONSpec(
public fun createSimBatteryPolicy(
batterySpec: BatteryPolicyJSONSpec,
- graph: FlowGraph,
+ engine: FlowEngine,
battery: SimBattery,
batteryAggregator: BatteryAggregator,
): BatteryPolicy {
return when (batterySpec) {
is SingleBatteryPolicyJSONSpec ->
SingleThresholdBatteryPolicy(
- graph,
+ engine,
battery,
batteryAggregator,
batterySpec.carbonThreshold,
)
is DoubleBatteryPolicyJSONSpec ->
DoubleThresholdBatteryPolicy(
- graph,
+ engine,
battery,
batteryAggregator,
batterySpec.lowerThreshold,
@@ -258,7 +258,7 @@ public fun createSimBatteryPolicy(
)
is RunningMeanPolicyJSONSpec ->
RunningMeanBatteryPolicy(
- graph,
+ engine,
battery,
batteryAggregator,
batterySpec.startingThreshold,
@@ -266,7 +266,7 @@ public fun createSimBatteryPolicy(
)
is RunningMeanPlusPolicyJSONSpec ->
RunningMeanPlusBatteryPolicy(
- graph,
+ engine,
battery,
batteryAggregator,
batterySpec.startingThreshold,