在Anylogic随机停车

时间:2018-03-20 17:45:00

标签: random simulation anylogic parking

我正在使用AnyLogic的交通道路图书馆,我知道可以在汽车源模块中定义汽车在停车场的初始位置。

我希望随机选择停车场空间。我知道有这个函数randomFreeSpaceIndex()返回随机选择的免费停车位的索引。

但我不知道如何在我的汽车来源上调用它或将其与CarMoveTo工具一起使用。到目前为止,这是我的model

感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

我非常确定您无法使用标准停车场,因此您不得不创建许多带有1个停车位的停车位,如下图所示: parking spot

完成后,现在您可以选择一个模型的随机停车位,例如: model

在这个模型中,我创建了一个停车场的集合...所有1个停车位: collection

在选择输出块中,询问是否有可用空间:

ArrayList <ParkingLot> freeSpaces=new ArrayList();
for(ParkingLot p : parkingSpaces){
    if(p.nFree()>0){
        freeSpaces.add(p);
    }
}
int randomSpace=uniform_discr(0,freeSpaces.size()-1);
return freeSpaces.get(randomSpace);

并在carMoveTo中调用函数selectRandomParkingSpace(): randomParkingSpace

selectRandomParkingSpace使用以下代码:

function req_m () {
  var json = JSON.parse(this.responseText);
  console.log("Matching Rule cree avec succes");

  matching_id = json[Object.keys(json)[Object.keys(json).length -1]].id;     
  console.log(matching_id);
  var matching_name = json[Object.keys(json)[Object.keys(json).length - 1]].name;
}

这是我的解决方案。