문제

내가 사용하는 이산 사건 시뮬레이터 라는 ns-2 를 사용하여 제작되었 Tcl 및 C++.내가 하려고 쓰는 코드에서 TCL:

set ns [new Simulator]

set state 0

$ns at 0.0 "puts \"At 0.0 value of state is: $state\""
$ns at 1.0 "changeVal"
$ns at 2.0 "puts \"At 2.0 values of state is: $state\""

proc changeVal {} {
    global state
    global ns
    $ns at-now "set state [expr $state+1]"
    puts "Changed value of state to $state"
}

$ns run

여기에 출력:

At 0.0 value of state is: 0
Changed value of state to 0
At 2.0 values of state is: 0

의 값을 주지 않는 것을 변경합니다.나는 확실하지 않으면 내가 뭔가 잘못 사용하 TCL.사람은 아이디어로 무엇이 있는지 잘못된 것까요?

편집:도움을 주셔서 감사합니다.실제로,ns-2 무언가가는 내가 없어(하지 않는 내가 다시 컴파일 시뮬레이터 자).나는 제안하고 여기에 출력:

코드:

set ns [new Simulator]

set state 0

$ns at 0.0 "puts \"At 0.0 value of state is: $state\""
$ns at 1.0 "changeVal"
$ns at 9.0 "puts \"At 2.0 values of state is: $state\""

proc changeVal {} {
    global ns
    set ::state [expr {$::state+1}]
    $ns at-now "puts \"At [$ns now] changed value of state to $::state\""
}

$ns run

출력 결과는 다음과 같습니다.

At 0.0 value of state is: 0
At 1 changed value of state to 1
At 2.0 values of state is: 0

과를 위해 코드:

set ns [new Simulator]

set state 0

$ns at 0.0 "puts \"At 0.0 value of state is: $state\""
$ns at 1.0 "changeVal"
$ns at 9.0 "puts \"At 2.0 values of state is: $state\""

proc changeVal {} {
    global ns
    set ::state [expr {$::state+1}]
    $ns at 1.0 {puts "At 1.0 values of state is: $::state"}
}

$ns run

출력 결과는 다음과 같습니다.

At 0.0 value of state is: 0
At 1.0 values of state is: 1
At 2.0 values of state is: 0

작동하지 않는 것...가 확실하지 않은 경우 해당 문제가 ns2 또는 내 코드...

도움이 되었습니까?

해결책

Supriyo가 언급했듯이, 이것은 매우 넓은 주제입니다.그러나 Microsoft는 문서 관리 계획을 큰 자세한 내용으로 문서화했습니다.여기에서 시작하십시오 : http://technet.microsoft.com./en-us/library/cc263266(v=office.14).aspx

다른 팁

문제는 당신이 대체하는 가치의 변수 즉시,그리고 시간에 코드를 평가합니다.필요하신을 연기 변경하십시오.따라서,대신:

$ns at 2.0 "puts \"At 2.0 values of state is: $state\""

이렇:

$ns at 2.0 {puts "At 2.0 values of state is: $state"}

그것의 좋은 방법은 아무것도 넣은 더 복잡한 통화의 명령 대체 절차를 수행할 때 호출을 다음과 같다.훨씬 쉽게 작동하기 위해 맞다.

[편집]
또한, at-now 은 여전히 연기를 하고 몸을 때까지 후 현재 at 반환합니다.

I am not sure why this works but it works:

set ns [new Simulator]

set state 0

proc changeVal {} {
    global ns
    incr ::state
    $ns at-now {puts "Local::At [$ns now] values of state is: $::state"}
}

$ns at 0.0 "puts \"Global::At 0.0 value of state is: $state\""
changeVal
$ns at 9.0 "puts \"Global::At 2.0 values of state is: $state\""

$ns run

Output:

Global::At 0.0 value of state is: 0
Local::At 0 values of state is: 1
Global::At 2.0 values of state is: 1

If anyone knows an explanation, that would be great.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top