英文:
trouble calling the correct instances in my function and in my "moveTo" block
问题
I want to fill a pie chart but am having trouble calling the correct instances in my function and in my "moveTo" block.
我想填充一个饼图,但在我的函数和“moveTo”块中调用正确的实例时遇到了问题。
I have a function that returns nothing (just action) with the name AGVundTyp.
这是我的一个不返回任何内容(只有操作)的函数,名为AGVundTyp。
This is my function body:
这是我的函数主体:
if ((Package)agent.p_type==0 && ((AGV)agent.p_type==0)) {
AGV1_Type1++;
} else if ((Package)agent.p_type==1 && ((AGV)agent.p_type==0)){
AGV1_Type2++;
} else if ((Package)agent.p_type==2 && ((AGV)agent.p_type==0)){
AGV1_Type3++;
}
else {
error ("error");
}
if ((Package)agent.p_type==0 && ((AGV)agent.p_type==1) ){
AGV2_Type1++;
} else if ((Package)agent.p_type==1 && ((AGV)agent.p_type==1)){
AGV2_Type2++;
} else if ((Package)agent.p_type==2 && ((AGV)agent.p_type==1)){
AGV2_Type3++;
}
else {
error ("error");
}
if ((Package)agent.p_type==0 && ((AGV)agent.p_type==2)) {
AGV3_Type1++;
} else if ((Package)agent.p_type==1 && ((AGV)agent.p_type==2)){
AGV3_Type2++;
} else if ((Package)agent.p_type==2 && ((AGV)agent.p_type==2)){
AGV3_Type3++;
}
else {
error ("error");
I have the error messages:
我收到以下错误消息:
-
agent cannot be resolved to a variable
-
Incompatible operand types AGV and int
-
Incompatible operand types Packages and int
-
代理无法解析为变量
-
AGV和int的操作数类型不兼容
-
Packages和int的操作数类型不兼容
I have in my class AGV a parameter with p_type (int) and in my class Package also a parameter with p_type (int) .
在我的AGV类中,我有一个p_type(int)参数,在我的Package类中也有一个p_type(int)参数。
The initialization of the types of package were set in the source at creation.
包的类型初始化是在创建时设置的。
The initialization of the types of AGV was set in the respective resource pool. There are three different ResourcePool (for each type of AGV one ResourcePool).
AGV类型的初始化是在各自的资源池中设置的。有三个不同的ResourcePool(每种类型的AGV一个ResourcePool)。
The function should be called in the moveTo operator and compare the two types of orders respectively. Since I have the same parameters, I don't know how to call it so that it clearly distinguishes which type of AGV/package is meant.
该函数应该在moveTo操作符中调用,并分别比较两种类型的订单。由于我有相同的参数,我不知道如何调用它,以清楚区分是指哪种类型的AGV/包裹。
How do I solve my problem that I can compare the agents properly and add them in my pie chart?
如何解决我的问题,以便正确比较代理并将它们添加到我的饼图中?
I would really appreciate the help.
我会非常感激帮助。
英文:
I want to fill a pie chart but am having trouble calling the correct instances in my function and in my "moveTo" block.
I have a function that returns nothing (just action) with the name AGVundTyp.
This is my function body:
if ((Package)agent.p_type==0 && ((AGV)agent.p_type==0)) {
AGV1_Type1++;
} else if ((Package)agent.p_type==1 && ((AGV)agent.p_type==0)){
AGV1_Type2++;
} else if ((Package)agent.p_type==2 && ((AGV)agent.p_type==0)){
AGV1_Type3++;
}
else {
error ("error");
}
if ((Package)agent.p_type==0 && ((AGV)agent.p_type==1) ){
AGV2_Type1++;
} else if ((Package)agent.p_type==1 && ((AGV)agent.p_type==1)){
AGV2_Type2++;
} else if ((Package)agent.p_type==2 && ((AGV)agent.p_type==1)){
AGV2_Type3++;
}
else {
error ("error");
}
if ((Package)agent.p_type==0 && ((AGV)agent.p_type==2)) {
AGV3_Type1++;
} else if ((Package)agent.p_type==1 && ((AGV)agent.p_type==2)){
AGV3_Type2++;
} else if ((Package)agent.p_type==2 && ((AGV)agent.p_type==2)){
AGV3_Type3++;
}
else {
error ("error");
I have the error messages:
- agent cannot be resolved to a variable
- Incompatible operand types AGV and int
- Incompatible operand types Packages and int
I have in my class AGV a parameter with p_type (int) and in my class Package also a parameter with p_type (int) .
The initialization of the types of package were set in the source at creation.
The initialization of the types of AGV was set in the respective resource pool. There are three different ResourcePool (for each type of AGV one ResourcePool).
The function should be called in the moveTo operator and compare the two types of orders respectively. Since I have the same parameters, I don't know how to call it so that it clearly distinguishes which type of AGV/package is meant.
How do I solve my problem that I can compare the agents properly and add them in my pie chart?
I would really appreciate the help.
答案1
得分: 2
这里有很多问题... 一些示例:
if ((Package)agent.p_type==0 && ((AGV)agent.p_type==0)) {
你不能随意将一个代理对象强制转换成你想要的类型,而应该像这样处理:
if (agent instanceof Package) {
}else if (agent instanceof AGV) {
}
其次,使用集合或数组来计数,而不是原始变量,不要使用 AGV1_Type2++;
,而是使用:
AGV[1][2]++;
你还需要确保代理对象是你函数的输入,而且必须是 Agent 类型,这样你才能在函数内部将其强制转换为不同的类型。
你可能还有其他 10 处错误... 所以确保你知道自己在做什么,简化代码并测试较小的代码块,以查看哪里出错。
英文:
there are a lot of problems here... some examples:
if ((Package)agent.p_type==0 && ((AGV)agent.p_type==0)) {
you can't just cast an agent to whatever you want instead you should do something like this
if(agent instanceof Package){
}else if(agent instanceof AGV){
}
Second use a collection or arrays instead of raw variables to count
instead of AGV1_Type2++;
AGV[1][2]++;
You also need to be sure that agent is an input to your function, and it has to be of the type Agent so you can cast it to different things within the function
You have probably 10 other errors... so make sure you know what you are doing, simplify and test smaller chunks of code in order to see what you are doing wrong
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论