+std::deque<VirtualMachine*> VirtualMachine::allVms_;
+
+s4u::Host *VMModel::createVM(const char *name, sg_host_t host_PM)
+{
+ VirtualMachine* vm = new VirtualMachine(this, name, host_PM);
+ onVmCreation(vm);
+ return vm->piface_;
+}
+
+/* In the real world, processes on the guest operating system will be somewhat degraded due to virtualization overhead.
+ * The total CPU share these processes get is smaller than that of the VM process gets on a host operating system. */
+// const double virt_overhead = 0.95;
+const double virt_overhead = 1;
+
+double VMModel::next_occuring_event(double now)
+{
+ /* TODO: update action's cost with the total cost of processes on the VM. */
+
+ /* 1. Now we know how many resource should be assigned to each virtual
+ * machine. We update constraints of the virtual machine layer.
+ *
+ * If we have two virtual machine (VM1 and VM2) on a physical machine (PM1).
+ * X1 + X2 = C (Equation 1)
+ * where
+ * the resource share of VM1: X1
+ * the resource share of VM2: X2
+ * the capacity of PM1: C
+ *
+ * Then, if we have two process (P1 and P2) on VM1.
+ * X1_1 + X1_2 = X1 (Equation 2)
+ * where
+ * the resource share of P1: X1_1
+ * the resource share of P2: X1_2
+ * the capacity of VM1: X1
+ *
+ * Equation 1 was solved in the physical machine layer.
+ * Equation 2 is solved in the virtual machine layer (here).
+ * X1 must be passed to the virtual machine laye as a constraint value.
+ **/
+
+ /* iterate for all virtual machines */
+ for (VirtualMachine *ws_vm : VirtualMachine::allVms_) {
+ Cpu *cpu = ws_vm->cpu_;
+ xbt_assert(cpu, "cpu-less host");
+
+ double solved_value = ws_vm->action_->getVariable()->value;
+ XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->getName(), ws_vm->getPm()->name().c_str());
+
+ // TODO: check lmm_update_constraint_bound() works fine instead of the below manual substitution.
+ // cpu_cas01->constraint->bound = solved_value;
+ xbt_assert(cpu->getModel() == surf_cpu_model_vm);
+ lmm_system_t vcpu_system = cpu->getModel()->getMaxminSystem();
+ lmm_update_constraint_bound(vcpu_system, cpu->getConstraint(), virt_overhead * solved_value);
+ }
+
+ /* 2. Calculate resource share at the virtual machine layer. */
+ adjustWeightOfDummyCpuActions();
+
+ /* 3. Ready. Get the next occuring event */
+ return surf_cpu_model_vm->next_occuring_event(now);
+}
+