Class: Roby::EventStructure::SchedulingConstraints

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/event_structure/temporal_constraints.rb

Defined Under Namespace

Modules: Extension

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**arguments) ⇒ SchedulingConstraints

Returns a new instance of SchedulingConstraints.



262
263
264
265
# File 'lib/roby/event_structure/temporal_constraints.rb', line 262

def initialize(**arguments)
    super
    @task_graph = Relations::BidirectionalDirectedAdjacencyGraph.new
end

Instance Attribute Details

#task_graphObject (readonly)

The graph of tasks related to each other by their events



260
261
262
# File 'lib/roby/event_structure/temporal_constraints.rb', line 260

def task_graph
  @task_graph
end

Instance Method Details

#add_edge(from, to, info) ⇒ Object



267
268
269
270
271
272
273
# File 'lib/roby/event_structure/temporal_constraints.rb', line 267

def add_edge(from, to, info)
    return unless super

    if from.respond_to?(:task) && to.respond_to?(:task)
        add_edge_in_task_graph(from.task, to.task)
    end
end

#add_edge_in_task_graph(from_task, to_task) ⇒ Object



275
276
277
278
279
280
281
282
283
284
# File 'lib/roby/event_structure/temporal_constraints.rb', line 275

def add_edge_in_task_graph(from_task, to_task)
    return if from_task == to_task

    if task_graph.has_edge?(from_task, to_task)
        count = task_graph.edge_info(from_task, to_task)
        task_graph.set_edge_info(from_task, to_task, count + 1)
    else
        task_graph.add_edge(from_task, to_task, 1)
    end
end

#clearObject



342
343
344
345
# File 'lib/roby/event_structure/temporal_constraints.rb', line 342

def clear
    super
    task_graph.clear
end

#merge(graph) ⇒ Object



297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/roby/event_structure/temporal_constraints.rb', line 297

def merge(graph)
    super

    # There's really no easy way to handle the merge nicely. Rebuild
    # the task graph
    task_graph.clear
    each_edge do |from, to|
        if from.respond_to?(:task) && to.respond_to?(:task)
            add_edge_in_task_graph(from.task, to.task)
        end
    end
end

Returns:

  • (Boolean)


338
339
340
# File 'lib/roby/event_structure/temporal_constraints.rb', line 338

def related_tasks?(ta, tb)
    task_graph.has_edge?(ta, tb)
end

#remove_edge(from, to) ⇒ Object



331
332
333
334
335
336
# File 'lib/roby/event_structure/temporal_constraints.rb', line 331

def remove_edge(from, to)
    super
    if from.respond_to?(:task) && to.respond_to?(:task)
        remove_edge_in_task_graph(from.task, to.task)
    end
end

#remove_edge_in_task_graph(from_task, to_task) ⇒ Object



286
287
288
289
290
291
292
293
294
295
# File 'lib/roby/event_structure/temporal_constraints.rb', line 286

def remove_edge_in_task_graph(from_task, to_task)
    return if from_task == to_task

    count = task_graph.edge_info(from_task, to_task)
    if count == 1
        task_graph.remove_edge(from_task, to_task)
    else
        task_graph.set_edge_info(from_task, to_task, count - 1)
    end
end

#remove_vertex(event) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/roby/event_structure/temporal_constraints.rb', line 315

def remove_vertex(event)
    if event.respond_to?(:task)
        each_in_neighbour(event) do |from|
            if from.respond_to?(:task)
                remove_edge_in_task_graph(from.task, event.task)
            end
        end
        each_out_neighbour(event) do |to|
            if to.respond_to?(:task)
                remove_edge_in_task_graph(event.task, to.task)
            end
        end
    end
    super
end

#replace(graph) ⇒ Object



310
311
312
313
# File 'lib/roby/event_structure/temporal_constraints.rb', line 310

def replace(graph)
    super
    task_graph.replace(graph.task_graph)
end