【问题标题】:Anylogic - Delay block for parkingAnylogic - 停车延迟块
【发布时间】:2020-03-14 18:16:55
【问题描述】:

有没有人知道如何获得一个函数的值来指示街区是否有任何空停车位。 我正在使用队列,我尝试了函数nFree()spaceIndex(),但我发现这两个函数没有为类型定义

【问题讨论】:

  • 包含你的代码并展示你做了什么

标签: java delay anylogic parking


【解决方案1】:

希望我理解你的问题,下面是可能返回所有停车位的代码。

public class Parking {

    static int parkingSize = 10;

    static Object[] object = new Object[parkingSize];

    public static void main(String[] args) {

        add("java", 10);

        System.out.println(checkEmptyParkingSpot());

        emptyParkingSpot(10);

        System.out.println(checkEmptyParkingSpot());

    }

    // add the object in specicif location
    public static void add(String info, int position) {

        // if the position does not exist an erro will be thow
        if (position > object.length ) {
            throw new RuntimeException("The possition indicated does not exist in the park");
        }

        if (object[position - 1] != null) {
            throw new RuntimeException("The possition is ocupied");
        }

        object[position - 1] = info;

    }

    // to remove an object from the park and free the space
    public static void emptyParkingSpot(int position) {

        if (position > object.length ) {
            throw new RuntimeException("The possition indicated does not exist in the park");
        }

        if (object[position - 1] == null) {
            throw new RuntimeException("The possition isalready empty");
        }
        object[position - 1] = null;
    }

    // lists the empty spot 
    public static String checkEmptyParkingSpot() {

        String emptySpace = "".trim();

        for (int i = 0; i < object.length; i++) {

            // list the empty space
            if (object[i] == null) {
                emptySpace = emptySpace + (i + 1) + "\n";
            }

        }

        // if there is no space the message will be park full
        if (emptySpace.isEmpty()) {
            emptySpace = "Park is Full";
        }

        return emptySpace;
    }

}

【讨论】:

  • 抱歉,这与 AnyLogic 有什么关系吗?问题在于该工具及其特定的道路交通库,您的代码似乎是一些通用代码,在这里无济于事。还是我错过了什么
  • 非常感谢,但我在想是否可以在“进入”、“退出”字段中添加一些代码。因为老实说,我对 Anylogic 还是很陌生,我仍然不知道如何将 java 代码与我正在开发的模型链接起来。很抱歉
猜你喜欢
  • 2021-10-22
  • 2020-06-28
  • 2016-02-08
  • 2018-08-29
  • 1970-01-01
  • 2021-10-07
  • 2019-02-08
  • 2021-02-17
  • 1970-01-01
相关资源
最近更新 更多