using parfor inside constraint function for gamultiobj

조회 수: 2 (최근 30일)
Pourshid Fani
Pourshid Fani 2017년 6월 5일
답변: Arnav Mendiratta 2017년 6월 12일
Hi,
I'm currently trying to run a simscape simulation inside of my constraint function for my multi objective genetic algorithm (gamultiobj). The ga runs in vectorized 'mode', but the simscape simulation inside the constraint function runs in a for loop (which I'm trying to make a parfor loop).
I'm wondering why I get the following error.
Error using lmConstraintMGAp1 (line 24)
Error detected on workers 1 2 3 4.
Error in linkmass_optimizationMGAp1>@(x)lmConstraintMGAp1(x,cd,E,l,qdata)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in constrValidate (line 21)
[tmpCineq,tmpCeq] = nonlcon([Iterate.x Iterate.x]');
Error in gacommon (line 132)
[LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, ...
Error in gamultiobj (line 260)
~,options] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub,nonlcon,[],options,user_options);
Error in linkmass_optimizationMGAp1 (line 30)
[x,fval, eflag] = gamultiobj(objf, nvars, A, b, Aeq, beq, lb, ub, cfunc,opts);
Caused by:
Error using lmConstraintMGAp1 (line 24)
Index exceeds matrix dimensions.
Error using lmConstraintMGAp1 (line 24)
Index exceeds matrix dimensions.
Error using lmConstraintMGAp1 (line 24)
Index exceeds matrix dimensions.
Error using lmConstraintMGAp1 (line 24)
Index exceeds matrix dimensions.
Failure in initial user-supplied nonlinear constraint function evaluation.
linkmass_optimizationMGAp1 is the script that calls the optimization lmConstraintMGAp1 is the constraint function.
thanks

답변 (1개)

Arnav Mendiratta
Arnav Mendiratta 2017년 6월 12일
It is not recommended to run the simulations in a parfor loop. There are many things that might break because all the Simulink features might not support parfor workflows.
If you want to simulate dynamic systems in parallel, use parsim instead.
If you do want to use the "sim" command in "parfor" loop, make sure you are using the recommended workflows documented here:
https://www.mathworks.com/help/simulink/ug/running-parallel-simulations.html#bt33wws

카테고리

Help CenterFile Exchange에서 Simscape Multibody에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by