module main {
    type state_t = enum { RED, GREEN, PENDING, YELLOW };
    var current_state : state_t;
    var count : int;
    input pedestrian : boolean;
    output sigG, sigY, sigR : boolean;

    init {
        current_state = RED;
        count = 0;
        sigG = false;
        sigY = false;
        sigR = true;
    }

    next {
        if (current_state == RED) {
            sigR' = true;
            sigG' = false;
            sigY' = false;
            if (count >= 60) {
                current_state' = GREEN;
                count' = 0;
            } else {
                count' = count + 1;
            }
        } else if (current_state == GREEN) {
            sigG' = true;
            sigY' = false;
            sigR' = false;
            if (pedestrian && count >= 60) {
                current_state' = YELLOW;
                count' = 0;
            } else if (pedestrian) {
                current_state' = PENDING;
                count' = count + 1;
            } else {
                count' = count + 1;
            }
        } else if (current_state == PENDING) {
            sigG' = true;
            sigY' = false;
            sigR' = false;
            if (count >= 60) {
                current_state' = YELLOW;
                count' = 0;
            } else {
                count' = count + 1;
            }
        } else if (current_state == YELLOW) {
            sigY' = true;
            sigG' = false;
            sigR' = false;
            if (count >= 5) {
                current_state' = RED;
                count' = 0;
            } else {
                count' = count + 1;
            }
        }
    }

    control {
        v = simulate(120); // Simulate for 120 seconds to observe two full cycles
        print_trace;
    }
}
