NetLogo:限制按特定补丁收费的用户数时出现的问题

问题描述 投票:1回答:1

我正在一个项目中,对电动汽车充电对电网的影响进行建模,并对汽车用户的驾驶和充电习惯进行建模/模拟。我的代码中出现无法解决的问题。

每个位置的充电端口数量有限。例如,WORK总共有2个终端,因此只有2个采用者可以在那同时收费(先到先得)。我想做的是,当2个采用者到达工作位置时,他们开始收费(如果需要,即“ charge-status” = true)。任何其他采用者都将等到该端口可用为止。完成充电的收养者应该腾出等待端口中的充电端口,即使他们没有离开。

这是我所做的努力(代码)的一部分:

to go
    ...

    charge-car      ; sets the charging-status based on state-of-charge.

    ask adopters
    [
      if charging? and not marked?
      [
        ifelse remaining-ports != 0
        [
          set remaining-ports max list (remaining-ports - 1) 0
          set marked? true
        ]
        [set occupied? true]
      ]

      if marked? and not charging?
      [
        set remaining-ports min list (remaining-ports + 1) terminals
        set marked? false
        set occupied? false
      ]
    ]
    ask adopters with [charging? and marked?]
    [
      set color green
      let battery0 battery
      let charging-speed0 charging-speed
      let battery1 max list 0 ( battery + charging-speed0 )
      set battery min list battery1 battery-capacity
      let charged min list ( battery - battery0 ) charging-speed0
      set charge-demand charge-demand + charged
      set soc battery / battery-capacity
      set range-left battery / discharge-patch
    ]
  tick
end

现在,问题是这样的:在地图上有多个带有充电端口的位置。即使对于所有位置和代理而言,该代码都具有相同的算法,但该代码在某些位置上会给出不同的结果。例如,如果两个端口都在某些位置被占用,则“被占用?”对于某些位置将是正确的,但并非所有端口都已启用的所有位置都是正确的。我的意思是说,这显示出相当随机的响应。

有人可以帮我吗?还有另一种方法可以做我想做的事吗?另外,如果您需要更多信息以了解我的情况,请告诉我。

谢谢!

编辑:这是我的to go]代码

to go
...
ask adopters
  [
    if patch-here = current-loc ; choose next target only when reached at a destination (current location)
    [
      choose-target
      set nearest-station min-one-of patches with [location = "charging-station"][distance myself]
    ] ; choose target based on start time and current location

    ; go to target only when NOT at the arbitrary target location
    if target != [0 0]
    [
      let dist-to-targ distance-between current-loc target
      let dist-to-station distance-between current-loc nearest-station
      ifelse dist-to-targ > range-left and dist-to-station < range-left
      [go-to-station nearest-station]
      [go-to-target]
    ]

    if charging = "Charge Car Now"
    [charge-car]
...
 ]

charge-car在哪里

to charge-car
  if patch-here = current-loc and charging-point
  [
    ifelse soc < 1
    [
      if charge-power = 1
      [
        set charging-speed 1 / 12
        set charging-status true
      ]
      if charge-power = 2
      [
        set charging-speed 6.6 / 12
        set charging-status true
      ]
    ]
    [
      set charging-status false
      set color blue
    ]
  ]
end

[go-to-target

to go-to-target
  ifelse patch-here != target
  [
    ; move towards destination and use fuel
    face target
;    set marked? false
    set color blue
    ifelse distance target <= speed
    [set speed1 0.3 * distance target] ; decrease speed as target gets nearer
    [set speed1 speed]
    forward speed1
    set moving? true
    set charging-status false
    if marked?
    [
      set rem-term min list (rem-term + 1) terminals
      type patch-here type "Updated ports" print rem-term
      set marked? false
      set occupied? false
    ]

  ]
  [
    move-to target
    if target != [0 0]
    [set dist-trav distance-between current-loc target]
    set current-loc target
    set moving? false
    set dwell dwell-acq day-ind time-ind position [location] of target places ; calculate dwell time based on arrival time at target
    ifelse dwell < 0
    [
      set dwell 288 - (ticks mod 288) ; spend rest of the time till 24:00 at that location
      set dwell-flag 1
    ]
    [set dwell-flag 0]
    if current-loc = target
    [
      set arrival-time (ticks mod 288)
      set start-time (dwell + arrival-time) mod 288
      set target [0 0]
      set battery battery - (discharge-patch * dist-trav) ; discharge based on distance traveled per tick
      set soc battery / battery-capacity
      set range-left battery / discharge-patch
      if battery < 0
      [set battery 0]
      if soc < 0
      [set soc 0]
    ]
   ]
end

其中rem-termremaining-ports相同,charging-statuscharging?相同。我尝试在go-to-target函数中添加相同的代码,因为充电状态首先会在此处更改,但这并没有显示我得到的结果的任何变化。

我正在一个项目中,对电动汽车充电对电网的影响进行建模,并对汽车用户的驾驶和充电习惯进行建模/模拟。我的代码中出现了一个问题...

netlogo
1个回答
2
投票

我看不到您的代码明显有问题。之所以会发生这种情况,是因为您有多个ask turtles块,并且在第一个块中算出了意图,但是直到第二个块才开始执行操作。就您而言,我可以看到您在第一块中更新了端口计数,因此这并不直接适用。

© www.soinside.com 2019 - 2024. All rights reserved.