{
  "defaults": {
    "candidateCount": 25
  },
  "schemaVersion": "akoflow.scheduler/v1",
  "id": "moheft",
  "name": "MOHEFT",
  "description": "Pareto list scheduling for completion time and financial cost (Durillo et al., 2012).",
  "objective": "pareto",
  "multiple": true,
  "origin": "plugin",
  "exclusive": false,
  "source": "package main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"math\"\n\t\"sort\"\n)\n\n// MOHEFT implements Algorithm 2 of Durillo, Fard and Prodan (CloudCom 2012).\n// Its frontier is ordered by Pareto dominance, then NSGA-II crowding distance.\n// Task timing uses Akoflow's CPU lanes and fixed-link transfer estimates.\n// Prices follow the paper's task-additive model, not PRISM's VM active window.\nfunc Schedule(input Input) ([]Plan, error) {\n\tmodel, err := newMOModel(input)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tk := 25\n\tif raw, ok := input.Configuration[\"candidateCount\"]; ok {\n\t\tnumber, ok := raw.(float64)\n\t\tif !ok || math.Trunc(number) != number || number \u003c 1 || number \u003e 1000 {\n\t\t\treturn nil, fmt.Errorf(\"candidateCount must be an integer between 1 and 1000\")\n\t\t}\n\t\tk = int(number)\n\t}\n\tfrontier := []moState{model.empty()}\n\tfor _, task := range model.order {\n\t\tnext := make([]moState, 0, len(frontier)*len(model.resources))\n\t\tfor _, state := range frontier {\n\t\t\tfor resource := range model.resources {\n\t\t\t\tcandidate, ok := model.place(state, task, resource)\n\t\t\t\tif ok {\n\t\t\t\t\tnext = append(next, candidate)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif len(next) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"no feasible placement for activity %q\", model.tasks[task].ID)\n\t\t}\n\t\tfrontier = moSelect(next, k)\n\t}\n\tplans := make([]Plan, 0, len(frontier))\n\tfor i, state := range frontier {\n\t\tp := model.plan(state, i)\n\t\tp.Metadata[\"candidateCount\"] = len(frontier)\n\t\tplans = append(plans, p)\n\t}\n\treturn plans, nil\n}\n\ntype moLink struct {\n\tSourceResourceID, TargetResourceID                   string\n\tBandwidthBitsPerSecond, LatencySeconds, PricePerByte float64\n\tBidirectional                                        bool\n}\ntype moProfile struct {\n\tActivityTypeID, ResourceID, ModelVersion string\n\tRuntimeSeconds                           float64\n}\ntype moData struct {\n\tProducerActivityID, ConsumerActivityID string\n\tSizeBytes                              int64\n}\ntype moEdge struct {\n\ttask  int\n\tbytes int64\n}\ntype moRecord struct {\n\tassignment Assignment\n\tresource   int\n}\ntype moInterval struct{ start, finish float64 }\ntype moMemory struct {\n\tstart, finish float64\n\tbytes         int64\n}\ntype moBlock [64]*moRecord\n\n// Persistent, chunked placement vectors avoid copying the complete DAG on every expansion.\ntype moState struct {\n\tblocks         []*moBlock\n\tslots          [][][]moInterval\n\tmemory         [][]moMemory\n\tmakespan, cost float64\n\tsignature      uint64\n}\n\nfunc (s moState) get(task int) *moRecord {\n\tif s.blocks[task/64] == nil {\n\t\treturn nil\n\t}\n\treturn s.blocks[task/64][task%64]\n}\n\ntype moModel struct {\n\tinput             Input\n\ttasks             []Activity\n\tresources         []Resource\n\tparents, children [][]moEdge\n\torder             []int\n\tlinks             map[[2]string]moLink\n\truntimes          [][]float64\n\tlanes             []int\n\ttopologyID        string\n\tindex             map[string]int\n\tmemoryCheck       []bool\n}\n\nfunc newMOModel(input Input) (*moModel, error) {\n\tm := \u0026moModel{input: input, tasks: input.Request.Workflow.Activities, links: map[[2]string]moLink{}}\n\tif !moFinite(input.Request.Budget) || input.Request.Budget \u003c 0 || !moFinite(input.Request.DeadlineSeconds) || input.Request.DeadlineSeconds \u003c 0 {\n\t\treturn nil, fmt.Errorf(\"budget and deadline must be finite and nonnegative\")\n\t}\n\tif len(m.tasks) == 0 {\n\t\treturn nil, fmt.Errorf(\"workflow has no activities\")\n\t}\n\tif err := m.loadResources(); err != nil {\n\t\treturn nil, err\n\t}\n\tif err := m.loadGraph(); err != nil {\n\t\treturn nil, err\n\t}\n\tif err := m.loadRuntimes(); err != nil {\n\t\treturn nil, err\n\t}\n\torder, err := m.rankOrder()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tm.order = order\n\treturn m, nil\n}\nfunc (m *moModel) empty() moState {\n\ts := moState{blocks: make([]*moBlock, (len(m.tasks)+63)/64), slots: make([][][]moInterval, len(m.resources)),\n\t\tmemory: make([][]moMemory, len(m.resources)), signature: 14695981039346656037}\n\tfor r := range m.resources {\n\t\ts.slots[r] = make([][]moInterval, m.lanes[r])\n\t}\n\treturn s\n}\nfunc (m *moModel) rankOrder() ([]int, error) {\n\tindegree := make([]int, len(m.tasks))\n\tfor i := range indegree {\n\t\tindegree[i] = len(m.parents[i])\n\t}\n\ttopo := make([]int, 0, len(m.tasks))\n\tready := []int{}\n\tfor i, n := range indegree {\n\t\tif n == 0 {\n\t\t\tready = append(ready, i)\n\t\t}\n\t}\n\tfor len(ready) \u003e 0 {\n\t\tsort.Slice(ready, func(i, j int) bool { return m.tasks[ready[i]].ID \u003c m.tasks[ready[j]].ID })\n\t\ta := ready[0]\n\t\tready = ready[1:]\n\t\ttopo = append(topo, a)\n\t\tfor _, e := range m.children[a] {\n\t\t\tindegree[e.task]--\n\t\t\tif indegree[e.task] == 0 {\n\t\t\t\tready = append(ready, e.task)\n\t\t\t}\n\t\t}\n\t}\n\tif len(topo) != len(m.tasks) {\n\t\treturn nil, fmt.Errorf(\"workflow contains a cycle\")\n\t}\n\trank := make([]float64, len(m.tasks))\n\tposition := make([]int, len(m.tasks))\n\tfor i := len(topo) - 1; i \u003e= 0; i-- {\n\t\ta := topo[i]\n\t\tposition[a] = i\n\t\tavg := 0.0\n\t\tcount := 0\n\t\tfor r := range m.resources {\n\t\t\tif m.fits(a, r) {\n\t\t\t\tavg += m.runtimes[a][r]\n\t\t\t\tcount++\n\t\t\t}\n\t\t}\n\t\tif count == 0 {\n\t\t\treturn nil, fmt.Errorf(\"activity %s has no feasible resource\", m.tasks[a].ID)\n\t\t}\n\t\tavg /= float64(count)\n\t\ttail := 0.0\n\t\tfor _, e := range m.children[a] {\n\t\t\tcomm := 0.0\n\t\t\tpairs := 0\n\t\t\tfor r, from := range m.resources {\n\t\t\t\tfor q, to := range m.resources {\n\t\t\t\t\tif !m.fits(a, r) || !m.fits(e.task, q) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tseconds, ok := m.transfer(from.ID, to.ID, e.bytes)\n\t\t\t\t\tif ok {\n\t\t\t\t\t\tcomm += seconds\n\t\t\t\t\t\tpairs++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif pairs \u003e 0 {\n\t\t\t\tcomm /= float64(pairs)\n\t\t\t}\n\t\t\ttail = math.Max(tail, comm+rank[e.task])\n\t\t}\n\t\trank[a] = avg + tail\n\t}\n\t// Sorting by positive upward rank preserves precedence; position is the zero-edge tie break.\n\torder := append([]int(nil), topo...)\n\tsort.SliceStable(order, func(i, j int) bool {\n\t\tif rank[order[i]] != rank[order[j]] {\n\t\t\treturn rank[order[i]] \u003e rank[order[j]]\n\t\t}\n\t\treturn position[order[i]] \u003c position[order[j]]\n\t})\n\treturn order, nil\n}\nfunc (m *moModel) fits(task, resource int) bool {\n\ta, r := m.tasks[task], m.resources[resource]\n\tselector, _ := a.Metadata[\"resourceSelector\"].(string)\n\treturn (selector == \"\" || selector == r.ID) \u0026\u0026 r.CPUCapacity \u003e= a.Resources.CPU \u0026\u0026 r.MemoryBytes \u003e= a.Resources.MemoryBytes\n}\nfunc (m *moModel) transfer(from, to string, size int64) (float64, bool) {\n\tif from == to || size == 0 {\n\t\treturn 0, true\n\t}\n\tl, ok := m.links[[2]string{from, to}]\n\tif !ok {\n\t\treturn 0, false\n\t}\n\treturn l.LatencySeconds + float64(size)*8/l.BandwidthBitsPerSecond, true\n}\nfunc (m *moModel) place(s moState, task, resource int) (moState, bool) {\n\tif !m.fits(task, resource) {\n\t\treturn moState{}, false\n\t}\n\tr := m.resources[resource]\n\tparentFinish, transferTotal, ingress, egress := 0.0, 0.0, 0.0, 0.0\n\tfor _, e := range m.parents[task] {\n\t\tparent := s.get(e.task)\n\t\tif parent == nil {\n\t\t\treturn moState{}, false\n\t\t}\n\t\tfrom := m.resources[parent.resource]\n\t\tseconds, ok := m.transfer(from.ID, r.ID, e.bytes)\n\t\tif !ok {\n\t\t\treturn moState{}, false\n\t\t}\n\t\tparentFinish = math.Max(parentFinish, parent.assignment.PredictedFinishAt)\n\t\ttransferTotal = math.Max(transferTotal, seconds)\n\t\tif from.ID != r.ID {\n\t\t\tsize := float64(e.bytes)\n\t\t\tingress += size * moPrice(r.Metadata, \"ingressPricePerByte\")\n\t\t\tegress += size * moPrice(from.Metadata, \"egressPricePerByte\")\n\t\t}\n\t}\n\t// Paper Eqs. 1-2 use the maximum transfer, after the latest predecessor.\n\tready := parentFinish + transferTotal\n\truntime := m.runtimes[task][resource]\n\tlane, start := m.selectLane(s, task, resource, ready, runtime)\n\tfinish := start + runtime\n\t// Paper Eq. 4: CPU seconds + storage-time + remote ingress/egress. Bandwidth link tariffs do not replace the paper's ingress/egress prices.\n\tbilled := runtime + transferTotal\n\townCost := billed*r.PricePerSecond + float64(m.tasks[task].Resources.StorageBytes)*billed*moPrice(r.Metadata, \"storagePricePerByteSecond\") + ingress\n\trecord := \u0026moRecord{resource: resource,\n\t\tassignment: Assignment{Metadata: map[string]any{\"bootOverheadSeconds\": float64(0),\n\t\t\t\"resourceAvailableAtSeconds\": r.BootOverheadSeconds,\n\t\t\t\"containerOverheadSeconds\":   r.ContainerOverheadSeconds},\n\t\t\tActivityID: m.tasks[task].ID,\n\t\t\tPriority:   m.tasks[task].Priority,\n\t\t\tResourceID: r.ID,\n\t\t\tCoreID: fmt.Sprintf(\"%s-core-%d\",\n\t\t\t\tr.ID,\n\t\t\t\tlane+1),\n\t\t\tPredictedReadyAt:         ready,\n\t\t\tPredictedStartAt:         start,\n\t\t\tPredictedFinishAt:        finish,\n\t\t\tPredictedRuntimeSeconds:  runtime,\n\t\t\tPredictedTransferSeconds: transferTotal,\n\t\t\tPredictedCost:            ownCost + egress}}\n\tout := s\n\tout.blocks = append([]*moBlock(nil), s.blocks...)\n\tblock := \u0026moBlock{}\n\tif s.blocks[task/64] != nil {\n\t\t*block = *s.blocks[task/64]\n\t}\n\tblock[task%64] = record\n\tout.blocks[task/64] = block\n\tout.slots = append([][][]moInterval(nil), s.slots...)\n\tout.slots[resource] = append([][]moInterval(nil), s.slots[resource]...)\n\tintervals := append([]moInterval(nil), s.slots[resource][lane]...)\n\tintervals = append(intervals, moInterval{start - r.ContainerOverheadSeconds, finish})\n\tsort.Slice(intervals, func(i, j int) bool { return intervals[i].start \u003c intervals[j].start })\n\tout.slots[resource][lane] = intervals\n\tif m.memoryCheck[resource] {\n\t\tout.memory = append([][]moMemory(nil), s.memory...)\n\t\tout.memory[resource] = append(append([]moMemory(nil), s.memory[resource]...), moMemory{start - r.ContainerOverheadSeconds, finish, m.tasks[task].Resources.MemoryBytes})\n\t}\n\tout.makespan = math.Max(s.makespan, finish)\n\tout.cost = s.cost + ownCost + egress\n\tout.signature = (s.signature ^ uint64(resource+1)) * 1099511628211\n\treturn out, moFinite(out.cost) \u0026\u0026 moFinite(finish)\n}\nfunc (m *moModel) plan(s moState, index int) Plan {\n\tid := fmt.Sprintf(\"moheft-%d\", index+1)\n\tassignments := make([]Assignment, 0, len(m.tasks))\n\tfor resource := range m.resources {\n\t\tfor lane := 0; lane \u003c m.lanes[resource]; lane++ {\n\t\t\titems := []Assignment{}\n\t\t\tcore := fmt.Sprintf(\"%s-core-%d\", m.resources[resource].ID, lane+1)\n\t\t\tfor _, task := range m.order {\n\t\t\t\ta := s.get(task).assignment\n\t\t\t\tif a.CoreID == core {\n\t\t\t\t\titems = append(items, a)\n\t\t\t\t}\n\t\t\t}\n\t\t\tsort.SliceStable(items, func(i, j int) bool { return items[i].PredictedStartAt \u003c items[j].PredictedStartAt })\n\t\t\tfor order, a := range items {\n\t\t\t\ta.PredictedCost = m.finalTaskCost(s, a.ActivityID)\n\t\t\t\ta.ID = id + \"-\" + a.ActivityID\n\t\t\t\ta.PlanID = id\n\t\t\t\ta.OrderOnResource = order\n\t\t\t\tassignments = append(assignments, a)\n\t\t\t}\n\t\t}\n\t}\n\tfeasible := (m.input.Request.DeadlineSeconds \u003c= 0 || s.makespan \u003c= m.input.Request.DeadlineSeconds) \u0026\u0026 (m.input.Request.Budget \u003c= 0 || s.cost \u003c= m.input.Request.Budget)\n\treturn Plan{ID: id,\n\t\tWorkflowVersionID: m.input.Request.Workflow.ID,\n\t\tExecutionScopeID:  m.input.Request.ExecutionScope.ID,\n\t\tNetworkTopologyID: m.topologyID,\n\t\tAlgorithm:         \"moheft\",\n\t\tObjective:         \"pareto\",\n\t\tDeadlineSeconds:   m.input.Request.DeadlineSeconds,\n\t\tBudget:            m.input.Request.Budget,\n\t\tPredicted: Metrics{MakespanSeconds: s.makespan,\n\t\t\tCost:     s.cost,\n\t\t\tFeasible: feasible},\n\t\tAssignments: assignments,\n\t\tMetadata: map[string]any{\"algorithmReference\": \"doi:10.1109/CloudCom.2012.6427573\",\n\t\t\t\"costModel\":         \"moheft-task-additive\",\n\t\t\t\"timingModel\":       \"akoflow-cpu-lanes-fixed-link\",\n\t\t\t\"interferenceAware\": false}}\n}\nfunc moFinite(v float64) bool { return !math.IsNaN(v) \u0026\u0026 !math.IsInf(v, 0) }\nfunc moPrice(metadata map[string]any, key string) float64 {\n\tvalue, _ := metadata[key].(float64)\n\tif value \u003c 0 || !moFinite(value) {\n\t\treturn 0\n\t}\n\treturn value\n}\nfunc moDominates(a, b moState) bool {\n\treturn a.makespan \u003c= b.makespan \u0026\u0026 a.cost \u003c= b.cost \u0026\u0026 (a.makespan \u003c b.makespan || a.cost \u003c b.cost)\n}\nfunc moSelect(candidates []moState, k int) []moState {\n\t// Equal-objective mappings remain distinct: descendants may communicate differently.\n\tfront := make([]moState, 0, len(candidates))\n\tfor i, a := range candidates {\n\t\tdominated := false\n\t\tfor j, b := range candidates {\n\t\t\tif i != j \u0026\u0026 moDominates(b, a) {\n\t\t\t\tdominated = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !dominated {\n\t\t\tfront = append(front, a)\n\t\t}\n\t}\n\tif len(front) \u003c= k {\n\t\treturn front\n\t}\n\tdistance := make([]float64, len(front))\n\tindices := make([]int, len(front))\n\tfor i := range indices {\n\t\tindices[i] = i\n\t}\n\tfor objective := 0; objective \u003c 2; objective++ {\n\t\tvalue := func(i int) float64 {\n\t\t\tif objective == 0 {\n\t\t\t\treturn front[i].makespan\n\t\t\t}\n\t\t\treturn front[i].cost\n\t\t}\n\t\tsort.SliceStable(indices, func(i, j int) bool { return value(indices[i]) \u003c value(indices[j]) })\n\t\tlow, high := value(indices[0]), value(indices[len(indices)-1])\n\t\tif high == low {\n\t\t\tcontinue\n\t\t}\n\t\tdistance[indices[0]] = math.Inf(1)\n\t\tdistance[indices[len(indices)-1]] = math.Inf(1)\n\t\tfor i := 1; i \u003c len(indices)-1; i++ {\n\t\t\tdistance[indices[i]] += (value(indices[i+1]) - value(indices[i-1])) / (high - low)\n\t\t}\n\t}\n\tsort.SliceStable(indices, func(i, j int) bool {\n\t\ta, b := indices[i], indices[j]\n\t\tif distance[a] != distance[b] {\n\t\t\treturn distance[a] \u003e distance[b]\n\t\t}\n\t\tif front[a].makespan != front[b].makespan {\n\t\t\treturn front[a].makespan \u003c front[b].makespan\n\t\t}\n\t\tif front[a].cost != front[b].cost {\n\t\t\treturn front[a].cost \u003c front[b].cost\n\t\t}\n\t\treturn front[a].signature \u003c front[b].signature\n\t})\n\tselected := make([]moState, 0, k)\n\tfor _, i := range indices[:k] {\n\t\tselected = append(selected, front[i])\n\t}\n\treturn selected\n}\n\n// moMemoryReady returns the first blocking allocation's release if RAM would overflow.\nfunc moMemoryReady(usage []moMemory, start, finish float64, requested, capacity int64) float64 {\n\tif requested == 0 {\n\t\treturn start\n\t}\n\tevents := []float64{start}\n\tfor _, item := range usage {\n\t\tif item.start \u003e start \u0026\u0026 item.start \u003c finish {\n\t\t\tevents = append(events, item.start)\n\t\t}\n\t}\n\tsort.Float64s(events)\n\tfor _, at := range events {\n\t\tused := requested\n\t\tnext := math.Inf(1)\n\t\tfor _, item := range usage {\n\t\t\tif item.start \u003c= at \u0026\u0026 item.finish \u003e at {\n\t\t\t\tif item.bytes \u003e capacity-used {\n\t\t\t\t\treturn moFirstRelease(usage, at)\n\t\t\t\t}\n\t\t\t\tused += item.bytes\n\t\t\t\tnext = math.Min(next, item.finish)\n\t\t\t}\n\t\t}\n\t\tif used \u003e capacity {\n\t\t\treturn next\n\t\t}\n\t}\n\treturn start\n}\nfunc moFirstRelease(usage []moMemory, at float64) float64 {\n\tnext := math.Inf(1)\n\tfor _, item := range usage {\n\t\tif item.start \u003c= at \u0026\u0026 item.finish \u003e at \u0026\u0026 item.bytes \u003e 0 {\n\t\t\tnext = math.Min(next, item.finish)\n\t\t}\n\t}\n\treturn next\n}\n\nfunc (m *moModel) finalTaskCost(s moState, id string) float64 {\n\ttask := m.index[id]\n\tplaced := s.get(task)\n\tr := m.resources[placed.resource]\n\tbilled := placed.assignment.PredictedRuntimeSeconds + placed.assignment.PredictedTransferSeconds\n\tcost := billed*r.PricePerSecond + float64(m.tasks[task].Resources.StorageBytes)*billed*moPrice(r.Metadata, \"storagePricePerByteSecond\")\n\tfor _, e := range m.parents[task] {\n\t\tif s.get(e.task).resource != placed.resource {\n\t\t\tcost += float64(e.bytes) * moPrice(r.Metadata, \"ingressPricePerByte\")\n\t\t}\n\t}\n\tfor _, e := range m.children[task] {\n\t\tif s.get(e.task).resource != placed.resource {\n\t\t\tcost += float64(e.bytes) * moPrice(r.Metadata, \"egressPricePerByte\")\n\t\t}\n\t}\n\treturn cost\n}\n\nfunc (m *moModel) loadResources() error {\n\tallowed := map[string]bool{}\n\tfor _, id := range m.input.Request.ExecutionScope.EnvironmentVersionIDs {\n\t\tallowed[id] = true\n\t}\n\tfor _, r := range m.input.Request.Resources {\n\t\tif r.Type == \"batch_queue\" || r.Type == \"hpc_partition\" || r.Type == \"slurm_reservation\" {\n\t\t\tcontinue\n\t\t}\n\t\tif !r.Schedulable || !allowed[r.EnvironmentVersionID] {\n\t\t\tcontinue\n\t\t}\n\t\tif r.ID == \"\" || r.CPUCores \u003c 1 || !moFinite(r.CPUCapacity) || r.CPUCapacity \u003c= 0 || r.MemoryBytes \u003c 0 {\n\t\t\treturn fmt.Errorf(\"resource %s has invalid CPU/memory capacity\", r.ID)\n\t\t}\n\t\tif !moFinite(r.ComputeSpeedup) || r.ComputeSpeedup \u003c= 0 || !moFinite(r.PricePerSecond) || r.PricePerSecond \u003c 0 {\n\t\t\treturn fmt.Errorf(\"resource %q requires positive computeSpeedup and nonnegative pricePerSecond\", r.ID)\n\t\t}\n\t\tif r.BootOverheadSeconds \u003c 0 || !moFinite(r.BootOverheadSeconds) || r.ContainerOverheadSeconds \u003c 0 || !moFinite(r.ContainerOverheadSeconds) {\n\t\t\treturn fmt.Errorf(\"invalid overhead for %s\", r.ID)\n\t\t}\n\t\tfor _, key := range []string{\"storagePricePerByteSecond\", \"ingressPricePerByte\", \"egressPricePerByte\"} {\n\t\t\tif raw, ok := r.Metadata[key]; ok {\n\t\t\t\tnumber, valid := raw.(float64)\n\t\t\t\tif !valid || !moFinite(number) || number \u003c 0 {\n\t\t\t\t\treturn fmt.Errorf(\"invalid price %s on %s\", key, r.ID)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tm.resources = append(m.resources, r)\n\t}\n\tsort.Slice(m.resources, func(i, j int) bool { return m.resources[i].ID \u003c m.resources[j].ID })\n\tif len(m.resources) == 0 {\n\t\treturn fmt.Errorf(\"scope has no schedulable resources\")\n\t}\n\n\treturn nil\n}\n\nfunc (m *moModel) loadGraph() error {\n\tindex := map[string]int{}\n\tm.index = index\n\tfor i, a := range m.tasks {\n\t\tif a.ID == \"\" {\n\t\t\treturn fmt.Errorf(\"activity id is required\")\n\t\t}\n\t\tif _, ok := index[a.ID]; ok {\n\t\t\treturn fmt.Errorf(\"duplicate activity %q\", a.ID)\n\t\t}\n\t\tif a.Resources.MemoryBytes \u003c 0 || a.Resources.StorageBytes \u003c 0 {\n\t\t\treturn fmt.Errorf(\"negative resource requirement on %s\", a.ID)\n\t\t}\n\t\tindex[a.ID] = i\n\t\tif !moFinite(a.Resources.CPU) || a.Resources.CPU \u003c 0 || a.Resources.CPU \u003e 1 {\n\t\t\treturn fmt.Errorf(\"MOHEFT plugin requires single-lane activities; %q requests %g CPUs\", a.ID, a.Resources.CPU)\n\t\t}\n\t}\n\tvar topology struct {\n\t\tID    string\n\t\tLinks []moLink\n\t}\n\tif len(m.input.Request.NetworkTopology) \u003e 0 {\n\t\tif err := json.Unmarshal(m.input.Request.NetworkTopology, \u0026topology); err != nil {\n\t\t\treturn fmt.Errorf(\"network topology: %w\", err)\n\t\t}\n\t}\n\tm.topologyID = topology.ID\n\tfor _, l := range topology.Links {\n\t\tif !moFinite(l.BandwidthBitsPerSecond) || l.BandwidthBitsPerSecond \u003c= 0 || !moFinite(l.LatencySeconds) || l.LatencySeconds \u003c 0 || !moFinite(l.PricePerByte) || l.PricePerByte \u003c 0 {\n\t\t\treturn fmt.Errorf(\"invalid network link %s -\u003e %s\", l.SourceResourceID, l.TargetResourceID)\n\t\t}\n\t\tm.links[[2]string{l.SourceResourceID, l.TargetResourceID}] = l\n\t\tif l.Bidirectional {\n\t\t\tm.links[[2]string{l.TargetResourceID, l.SourceResourceID}] = l\n\t\t}\n\t}\n\n\treturn m.loadDependencies()\n}\n\nfunc (m *moModel) loadDependencies() error {\n\tedges := map[[2]int]int64{}\n\tfor _, d := range m.input.Request.Workflow.Dependencies {\n\t\tchild, cok := m.index[d.ActivityID]\n\t\tparent, pok := m.index[d.DependsOnActivityID]\n\t\tif !cok || !pok || parent == child {\n\t\t\treturn fmt.Errorf(\"invalid workflow dependency\")\n\t\t}\n\t\tedges[[2]int{parent, child}] = 0\n\t}\n\tfor _, raw := range m.input.Request.Workflow.DataDependencies {\n\t\tvar d moData\n\t\tif err := json.Unmarshal(raw, \u0026d); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tparent, pok := m.index[d.ProducerActivityID]\n\t\tchild, cok := m.index[d.ConsumerActivityID]\n\t\tif !pok || !cok || parent == child || d.SizeBytes \u003c 0 {\n\t\t\treturn fmt.Errorf(\"invalid data dependency\")\n\t\t}\n\t\tkey := [2]int{parent, child}\n\t\tif _, ok := edges[key]; !ok {\n\t\t\treturn fmt.Errorf(\"data edge must have a matching precedence dependency\")\n\t\t}\n\t\tif d.SizeBytes \u003e math.MaxInt64-edges[key] {\n\t\t\treturn fmt.Errorf(\"data size overflow\")\n\t\t}\n\t\tedges[key] += d.SizeBytes\n\t}\n\tm.parents = make([][]moEdge, len(m.tasks))\n\tm.children = make([][]moEdge, len(m.tasks))\n\tfor key, size := range edges {\n\t\tm.parents[key[1]] = append(m.parents[key[1]], moEdge{key[0], size})\n\t\tm.children[key[0]] = append(m.children[key[0]], moEdge{key[1], size})\n\t}\n\tfor i := range m.tasks {\n\t\tsort.Slice(m.parents[i], func(a, b int) bool { return m.tasks[m.parents[i][a].task].ID \u003c m.tasks[m.parents[i][b].task].ID })\n\t\tsort.Slice(m.children[i], func(a, b int) bool { return m.tasks[m.children[i][a].task].ID \u003c m.tasks[m.children[i][b].task].ID })\n\t}\n\n\treturn nil\n}\n\nfunc (m *moModel) loadCapacity() error {\n\tm.runtimes = make([][]float64, len(m.tasks))\n\tm.lanes = make([]int, len(m.resources))\n\tfor r, resource := range m.resources {\n\t\tcount := resource.CPUCores\n\t\tif count \u003c 1 {\n\t\t\tcount = 1\n\t\t}\n\t\tif resource.CPUCapacity \u003e 0 \u0026\u0026 resource.CPUCapacity \u003c float64(count) {\n\t\t\tcount = max(1, int(math.Floor(resource.CPUCapacity)))\n\t\t}\n\t\tif count \u003e 65536 {\n\t\t\treturn fmt.Errorf(\"resource has too many CPU lanes\")\n\t\t}\n\t\tm.lanes[r] = count\n\t}\n\tm.memoryCheck = make([]bool, len(m.resources))\n\tfor r, resource := range m.resources {\n\t\tmaxMemory := int64(0)\n\t\tfor task, a := range m.tasks {\n\t\t\tif m.fits(task, r) \u0026\u0026 a.Resources.MemoryBytes \u003e maxMemory {\n\t\t\t\tmaxMemory = a.Resources.MemoryBytes\n\t\t\t}\n\t\t}\n\t\tm.memoryCheck[r] = maxMemory \u003e resource.MemoryBytes/int64(m.lanes[r])\n\t}\n\n\treturn nil\n}\n\nfunc (m *moModel) loadRuntimes() error {\n\tif err := m.loadCapacity(); err != nil {\n\t\treturn err\n\t}\n\tprofiles := []moProfile{}\n\tfor _, raw := range m.input.Request.ActivityProfiles {\n\t\tvar p moProfile\n\t\tif err := json.Unmarshal(raw, \u0026p); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tprofiles = append(profiles, p)\n\t}\n\tfor i, a := range m.tasks {\n\t\tbase := 0.0\n\t\thasEstimate := a.Simulation != nil\n\t\tif a.Simulation != nil {\n\t\t\tbase = a.Simulation.DurationSeconds\n\t\t}\n\t\tif !moFinite(base) || base \u003c 0 {\n\t\t\treturn fmt.Errorf(\"invalid duration for %q\", a.ID)\n\t\t}\n\t\tm.runtimes[i] = make([]float64, len(m.resources))\n\t\tfor j, r := range m.resources {\n\t\t\thasEstimate := hasEstimate\n\t\t\tseconds := base / r.ComputeSpeedup\n\t\t\tfor _, p := range profiles {\n\t\t\t\tif p.ActivityTypeID == a.ActivityTypeID \u0026\u0026 p.ResourceID == r.ID \u0026\u0026 p.RuntimeSeconds \u003e 0 {\n\t\t\t\t\thasEstimate = true\n\t\t\t\t\tseconds = p.RuntimeSeconds\n\t\t\t\t\tif p.ModelVersion == \"reference-work-v1\" {\n\t\t\t\t\t\tif a.Simulation == nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"reference-work profile requires declared work for %s\", a.ID)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tseconds *= base\n\t\t\t\t\t} else if p.ModelVersion == \"compute-work-v1\" {\n\t\t\t\t\t\twork, known := a.Metadata[\"computeWorkUnits\"].(float64)\n\t\t\t\t\t\tif !known || !moFinite(work) || work \u003c 0 {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"compute-work profile requires declared work for %s\", a.ID)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tseconds *= work\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif !hasEstimate || !moFinite(seconds) || seconds \u003c 0 {\n\t\t\t\treturn fmt.Errorf(\"invalid runtime for %s on %s\", a.ID, r.ID)\n\t\t\t}\n\t\t\tm.runtimes[i][j] = seconds\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (m *moModel) selectLane(s moState, task, resource int, ready, runtime float64) (int, float64) {\n\tr := m.resources[resource]\n\tlane, start := 0, math.Inf(1)\n\tfor i, slots := range s.slots[resource] {\n\t\tavailable := math.Max(ready, r.BootOverheadSeconds)\n\t\tfor _, slot := range slots {\n\t\t\tif available+r.ContainerOverheadSeconds+runtime \u003c= slot.start {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif available \u003c slot.finish {\n\t\t\t\tavailable = slot.finish\n\t\t\t}\n\t\t}\n\t\tfor m.memoryCheck[resource] {\n\t\t\tretry := moMemoryReady(s.memory[resource], available, available+r.ContainerOverheadSeconds+runtime, m.tasks[task].Resources.MemoryBytes, r.MemoryBytes)\n\t\t\tif retry \u003c= available {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tavailable = retry\n\t\t\tfor _, slot := range slots {\n\t\t\t\tif available+r.ContainerOverheadSeconds+runtime \u003c= slot.start {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif available \u003c slot.finish {\n\t\t\t\t\tavailable = slot.finish\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcandidate := available + r.ContainerOverheadSeconds\n\t\tif candidate \u003c start {\n\t\t\tlane, start = i, candidate\n\t\t}\n\t}\n\n\treturn lane, start\n}\n",
  "documentation": "MOHEFT — Multi-Objective Heterogeneous Earliest Finish Time\n\nReference: Juan J. Durillo, Hamid Mohammadi Fard and Radu Prodan, “MOHEFT: A Multi-Objective List-based Method for Workflow Scheduling”, CloudCom 2012, pp. 185–192. DOI: 10.1109/CloudCom.2012.6427573.\n\nAlgorithm 2: process activities in B-rank/upward-rank order, expand every retained partial mapping on every feasible resource, remove Pareto-dominated partial schedules, and retain at most K using normalized NSGA-II crowding distance. Endpoints of each nonconstant objective receive infinite crowding distance. Equal-objective mappings remain distinct because their future transfer costs may differ. No weighted sum or PRISM search is substituted. K is candidateCount (default 25, accepted range 1–1000).\n\nIntegration model, explicitly distinguished from the paper's simplified equations:\n- The search procedure is MOHEFT. The AkôFlow adapter additionally honors CPU-lane availability (with gap insertion), scope membership, selectors, CPU/memory feasibility, boot and container overheads. Activities requiring more than one lane are rejected rather than scheduled incorrectly.\n- Execution receives the same cloud lifecycle enrichment as native plans, while the original task-additive forecast is preserved.\n- Initial machine boot is exported as absolute resourceAvailableAtSeconds, with explicit zero per-task boot overhead and the declared container overhead. Waiting past initial availability does not restart boot on descendants.\n- Timing takes the maximum predecessor finish plus the maximum incoming transfer (paper Eqs. 1–2), then inserts the computation into the earliest feasible CPU-lane gap. Communication uses directed fixed-bandwidth links plus their explicit latency; missing links invalidate cross-resource placements. There is no interference-aware correction, shared-link contention model, or implicit zero-latency connection.\n- Runtime uses activity/resource profiles when available, including reference-work-v1 and compute-work-v1; otherwise, measured reference duration divided by computeSpeedup. Missing/invalid work estimates are rejected.\n- The financial objective follows paper Eqs. 4–5: task execution/transfer duration × resource price, plus declared storage footprint × duration × storage price, plus remote ingress/egress. Optional resource metadata prices are storagePricePerByteSecond, ingressPricePerByte and egressPricePerByte (all per byte, with decimal units). Unspecified prices are zero. Explicit link PricePerByte tariffs are not substituted for the paper's ingress/egress model.\n- This is task-additive paper pricing, not the VM active-window/provisioning billing used by PRISM. The cost model is recorded as moheft-task-additive in each plan. Absolute predicted costs must not be treated as an identical-billing scientific comparison against PRISM. This integration does not claim to reproduce the paper's GridSim experiments or its numerical results.\n- Deadline and budget do not alter the MOHEFT search. Final plans are marked feasible/infeasible against the supplied limits. This heuristic does not guarantee a globally optimal Pareto frontier.\n\nThe plugin includes the complete implementation and only standard-library imports. The code can be inspected, edited and exported through Scheduling algorithms. It is not native and is not marked AkôFlow-exclusive.\n\nBDHEFT from Scientific Reports 15:19505 (2025), DOI: 10.1038/s41598-025-02654-z, is deliberately not implemented: the supplied publication has contradictory resource-selection rules (Eq. 37 vs. Algorithm 2 step 18) and heterogeneity formulas (Eqs. 10/12) whose unsquared deviations sum to zero. An authoritative clarification or reference implementation is required before installing an algorithm under that name.\n",
  "revision": 0,
  "activeRevision": 0,
  "status": ""
}