OpenModelica错误:“撕裂启发式词无法避免离散的迭代变量……”

发布于 2025-01-25 16:18:27 字数 3527 浏览 3 评论 0原文

我正在开发一群无人机的模拟。我在无人机前的检查区域造成了一个函数,但是当我尝试使用它时,它会显示此错误:

"The tearing heuristic was not able to avoid discrete iteration variables because otherwise the system could not have been torn".

这是功能:

function seeNearObject "Restituisce una lista contenente tutti gli oggetti rilevati dal sistema video del drone"
    
    InputReal x;
    InputReal y;
    InputReal z;

    InputReal x2[K.N];
    InputReal y2[K.N];
    InputReal z2[K.N];

    InputReal destX;
    InputReal destY; 
    InputReal destZ; 

    InputReal intrX[K.nIntr];
    InputReal intrY[K.nIntr];
    InputReal intrZ[K.nIntr];

    InputReal missX[K.nRocket];
    InputReal missY[K.nRocket];
    InputReal missZ[K.nRocket];

    InputReal statX[K.nStatObs];
    InputReal statY[K.nStatObs];
    InputReal statZ[K.nStatObs];

    OutputBool outneighbours[K.N];
    OutputBool outnearIntr[K.nIntr];
    OutputBool outnearMissile[K.nRocket];
    OutputBool outnearStatObs[K.nStatObs];

    protected
        Real viewField[3];

algorithm
    
    //Imposto i limiti del campo visivo. Data la direzione del drone, ogni asse avrà il suo limite.
    // viewField := findViewField(x,y,z, destX,destY,destZ);
    viewField := zeros(3);

    for j in 1:K.N loop
        outneighbours[j] := false;
        if((x2[j] >= x and x2[j] <= viewField[1]) or (x2[j] <= x and x2[j] >= viewField[1])) then
            if((y2[j] >= y and y2[j] <= viewField[2]) or (y2[j] <= y and y2[j] >= viewField[2])) then
                if((z2[j] >= z and z2[j] <= viewField[3]) or (z2[j] <= z and z2[j] >= viewField[3])) then
                    outneighbours[j] := true;
                end if;
            end if;
        end if;
    end for;

    for j in 1:K.nIntr loop
        outnearIntr[j] := false;
        if((intrX[j] >= x and intrX[j] <= viewField[1]) or (intrX[j] <= x and intrX[j] >= viewField[1])) then
            if((intrY[j] >= y and intrY[j] <= viewField[2]) or (intrY[j] <= y and intrY[j] >= viewField[2])) then
                if((intrZ[j] >= z and intrZ[j] <= viewField[3]) or (intrZ[j] <= z and intrZ[j] >= viewField[3])) then
                    outnearIntr[j] := true;
                end if;
            end if;
        end if;
    end for; 

    for j in 1:K.nRocket loop
        outnearMissile[j] := false;
        if((missX[j] >= x and missX[j] <= viewField[1]) or (missX[j] <= x and missX[j] >= viewField[1])) then
            if((missY[j] >= y and missY[j] <= viewField[2]) or (missY[j] <= y and missY[j] >= viewField[2])) then
                if((missZ[j] >= z and missZ[j] <= viewField[3]) or (missZ[j] <= z and missZ[j] >= viewField[3])) then
                    outnearMissile[j] := true;
                end if;
            end if;
        end if;
    end for; 

    for j in 1:K.nStatObs loop
        outnearStatObs[j] := false;
        if((statX[j] >= x and statX[j] <= viewField[1]) or (statX[j] <= x and statX[j] >= viewField[1])) then
            if((statY[j] >= y and statY[j] <= viewField[2]) or (statY[j] <= y and statY[j] >= viewField[2])) then
                if((statZ[j] >= z and statZ[j] <= viewField[3]) or (statZ[j] <= z and statZ[j] >= viewField[3])) then
                    outnearStatObs[j] := true;
                end if;
            end if;
        end if;
    end for; 

end seeNearObject;

所有输入是3D空间中的点,我有一个类似的功能(写得更好比这更明显。有错误吗?

I'm developing a simulation of a swarm of drones. I made a function for checking area in front of drones, but when i'm trying to use it it displays this error:

"The tearing heuristic was not able to avoid discrete iteration variables because otherwise the system could not have been torn".

This is the function:

function seeNearObject "Restituisce una lista contenente tutti gli oggetti rilevati dal sistema video del drone"
    
    InputReal x;
    InputReal y;
    InputReal z;

    InputReal x2[K.N];
    InputReal y2[K.N];
    InputReal z2[K.N];

    InputReal destX;
    InputReal destY; 
    InputReal destZ; 

    InputReal intrX[K.nIntr];
    InputReal intrY[K.nIntr];
    InputReal intrZ[K.nIntr];

    InputReal missX[K.nRocket];
    InputReal missY[K.nRocket];
    InputReal missZ[K.nRocket];

    InputReal statX[K.nStatObs];
    InputReal statY[K.nStatObs];
    InputReal statZ[K.nStatObs];

    OutputBool outneighbours[K.N];
    OutputBool outnearIntr[K.nIntr];
    OutputBool outnearMissile[K.nRocket];
    OutputBool outnearStatObs[K.nStatObs];

    protected
        Real viewField[3];

algorithm
    
    //Imposto i limiti del campo visivo. Data la direzione del drone, ogni asse avrà il suo limite.
    // viewField := findViewField(x,y,z, destX,destY,destZ);
    viewField := zeros(3);

    for j in 1:K.N loop
        outneighbours[j] := false;
        if((x2[j] >= x and x2[j] <= viewField[1]) or (x2[j] <= x and x2[j] >= viewField[1])) then
            if((y2[j] >= y and y2[j] <= viewField[2]) or (y2[j] <= y and y2[j] >= viewField[2])) then
                if((z2[j] >= z and z2[j] <= viewField[3]) or (z2[j] <= z and z2[j] >= viewField[3])) then
                    outneighbours[j] := true;
                end if;
            end if;
        end if;
    end for;

    for j in 1:K.nIntr loop
        outnearIntr[j] := false;
        if((intrX[j] >= x and intrX[j] <= viewField[1]) or (intrX[j] <= x and intrX[j] >= viewField[1])) then
            if((intrY[j] >= y and intrY[j] <= viewField[2]) or (intrY[j] <= y and intrY[j] >= viewField[2])) then
                if((intrZ[j] >= z and intrZ[j] <= viewField[3]) or (intrZ[j] <= z and intrZ[j] >= viewField[3])) then
                    outnearIntr[j] := true;
                end if;
            end if;
        end if;
    end for; 

    for j in 1:K.nRocket loop
        outnearMissile[j] := false;
        if((missX[j] >= x and missX[j] <= viewField[1]) or (missX[j] <= x and missX[j] >= viewField[1])) then
            if((missY[j] >= y and missY[j] <= viewField[2]) or (missY[j] <= y and missY[j] >= viewField[2])) then
                if((missZ[j] >= z and missZ[j] <= viewField[3]) or (missZ[j] <= z and missZ[j] >= viewField[3])) then
                    outnearMissile[j] := true;
                end if;
            end if;
        end if;
    end for; 

    for j in 1:K.nStatObs loop
        outnearStatObs[j] := false;
        if((statX[j] >= x and statX[j] <= viewField[1]) or (statX[j] <= x and statX[j] >= viewField[1])) then
            if((statY[j] >= y and statY[j] <= viewField[2]) or (statY[j] <= y and statY[j] >= viewField[2])) then
                if((statZ[j] >= z and statZ[j] <= viewField[3]) or (statZ[j] <= z and statZ[j] >= viewField[3])) then
                    outnearStatObs[j] := true;
                end if;
            end if;
        end if;
    end for; 

end seeNearObject;

All the inputs are point in a 3D space, and I have a similar function (written better than this) but it works clearly. Is there any error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡離愁欲言轉身 2025-02-01 16:18:27

您可能已经解决了这个问题,但是据我所知,代码可能会导致错误的两个问题。

(1)我在算法中看不到任何初始条件。在OpenModelica中,您应该始终具有

when initial() then [...] end when;

指定每个参数的启动值(输入中的参数)。

(2)读取与状态相关的变量var时,您应该始终使用pre(var)调用,以读取var的最后一个值,不是电流。那是因为OpenModelica使用代数公式来求解系统,如果您的模型具有循环(所有大型模型),则可能会导致代数公式不一致的问题。

像这样,

x := x + 2

应该总是

x := pre(x) + 2

希望这会有所帮助。 :)

you probably solved this, but as far as I can see there are two issues with the code that may be causing the error.

(1) I don't see any initial condition in the algorithm. In OpenModelica you should always have a

when initial() then [...] end when;

in which you specify the starting values of each parameter (except for the ones in Input).

(2) When reading a status related variable var you should always use the pre(var) call, to read the last value of var, not the current. That is because OpenModelica uses algebraic formulas to solve the system and if your model has loops (all big models do) it may lead to this very issue in which the algebraic formula is inconsistent.

Like so

x := x + 2

It should always be something like

x := pre(x) + 2

Hope this helps. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文