(use srfi-27) (use srfi-1) (define-syntax while (syntax-rules () ((while condition things ...) (do () ((not condition)) things ...)))) ;; (define x 0) ;; (while (< x 10) (set! x (+ x 1)) (display x)) (define (uniform min max) (+ min (* (- max min) (random-real)))) (define obra (graph ;; nodes and distributions `((T1 . ,(lambda () (uniform 32 48))) (T2 . ,(lambda () (uniform 40 60))) (T3 . ,(lambda () (uniform 15 25))) (T4 . ,(lambda () (uniform 10 15))) (T5 . ,(lambda () (uniform 10 15))) (T6 . ,(lambda () (uniform 6 10))) (T7 . ,(lambda () (uniform 18 24))) (T8 . ,(lambda () (uniform 4 8)))) ;; dependencies '((T2 . (T1)) (T3 . (T1 T2)) (T4 . (T2)) (T5 . (T2 T3)) (T6 . (T2)) (T7 . (T2 T4 T5)) (T8 . (T4 T5 T6 T7))))) (define (graph list-of-distributions list-of-dependencies) ;; start -> initializes alist of (TX . -1) (define (start lst) (map (lambda (node) (cons (car node) -1)) lst)) (define global-association-list (start list-of-distributions)) ;; nodes-left? -> is there any node with -1? (define (nodes-left?) (any (lambda (x) (= -1 (cdr x))) global-association-list)) ;; dependencies -> dependencies of a certain element (define (dependencies token) (cdr (assq token list-of-dependencies))) ;; dep-solved? -> all dependencies already have their value != 1 (define (dep-solved? token) (not (any (lambda (dep) (= -1 (cdr (assq dep global-association-list)))) (dependencies token)))) ;; need-and-ready -> items which have both all deps and need a time (define (need-and-ready) (filter (lambda (node) (and (= -1 (cdr node)) (dep-solved? (car node)))) global-association-list)) ;; compute-ready-nodes! -> compute nodes which have no precedence problem (define (compute-ready-nodes!) (for-each (lambda (node) (set-cdr! node (+ ((cdr (assq (car node) list-of-distributions))) something-here))) (need-and-ready))) (while (nodes-left?) (compute-ready-nodes!)) global-association-list)