Вверх ↑
Ответов: 8919
Рейтинг: 823
#1: 2019-11-02 23:17:03 ЛС | профиль | цитата
Gitarist, не стал вспоминать бухгалтерское "Линейное программирование" и искать алгоритмы Флойда-Уоршелла, Форда-Беллмана (вам советую), сделал собственный по ближайшей следующей точке, в сравнении с сортировкой выигрывает в 2--10 раз:
ОптимизацияПеремещений.jpg
Оптимизация перемещений


Add(MainForm,2953706,154,91)
{
Left=50
Top=50
Width=823
Height=479
Caption="Optimization movement"
link(onCreate,3352445:doEvent1,[])
}
Add(Image,15117092,560,245)
{
Left=270
Top=5
Width=400
Height=400
link(Bitmap,10462865:Var2,[])
}
Add(StringTable,1315472,287,112)
{
Left=5
Top=5
Width=125
Height=400
Columns=#4:X=50|4:Y=50|
Grid=0
Point(Strings)
}
Add(StringTable,7437200,490,182)
{
Left=140
Top=5
Width=125
Height=400
Color=32768
Font=[MS Sans Serif,8,1,32768,1]
Columns=#4:X=50|4:Y=50|
Grid=0
Point(Strings)
}
Add(Button,4852736,154,140)
{
Left=5
Top=410
Caption="New"
link(onClick,11703388:doWork3,[(221,146)])
}
Add(Hub,3352445,196,105)
{
link(onEvent1,6618759:doWork1,[])
link(onEvent2,11703388:doWork2,[])
}
Add(HubEx,11703388,217,112)
{
link(onEvent,6618759:doWork2,[])
}
Add(Bitmap,13120516,350,63)
{
HWidth=400
HHeight=400
FillColor=12639424
Point(doCreate)
}
Add(Edit,9021511,231,63)
{
Left=70
Top=410
Text="100"
DataType=2
}
Add(GetDataEx,11396531,350,105)
{
link(Data,13120516:Bitmap,[])
}
Add(MultiElementEx,9067928,392,196)
{
@Hint=#10:Сортировка|
link(onRes,6564702:doEvent1,[(431,202)(431,181)])
link(onEnd,7398956:doEvent1,[(431,209)(431,251)])
link(ArrStr,5874569:Var3,[(398,173)])
link(X_Y,4501545:Selected,[])
}
BEGIN_SDK
Add(EditMultiEx,893945,21,21)
{
WorkCount=#6:doRead|6:doSort|
EventCount=#5:onRes|5:onEnd|
DataCount=#6:ArrStr|3:X_Y|
Width=615
Height=340
VOffset=56
HOffset=49
link(doRead,14352417:doEvent1,[])
link(doSort,6738151:doCompare,[(39,90)(39,244)])
}
Add(MathParse,3898628,455,238)
{
DataCount=1
MathStr="round(%1/1000000,0.001)"
link(onResult,9401198:doCalc,[])
}
Add(RealArray,9808782,378,42)
{
RealArray=[]
}
Add(ArrayEnum,13575814,70,84)
{
link(onItem,2414822:doReplace,[])
link(onEndEnum,16038886:doSort,[(109,97)(109,174)])
link(Array,893945:ArrStr,[])
}
Add(Replace,2414822,119,84)
{
SubStr="X"
link(onReplace,15346706:doSplit,[])
}
Add(ArrayRW,8427566,378,98)
{
link(Array,454613:Var2,[])
}
Add(RealArray,12903765,420,56)
{
RealArray=[]
}
Add(ArrayRW,8511820,420,112)
{
link(Array,3577415:Var2,[])
}
Add(Hub,14352417,49,77)
{
link(onEvent1,5220703:doEvent1,[(81,83)(81,69)])
link(onEvent2,13575814:doEnum,[])
}
Add(Hub,5220703,189,63)
{
link(onEvent1,9808782:doClear,[(214,69)(214,62)])
link(onEvent2,12903765:doClear,[])
}
Add(FormatStr,9474807,560,238)
{
Mask="%1;%2"
link(onFString,3195000:doWork2,[])
link(Str1,3898628:Result,[(566,229)(552,229)(552,278)(461,278)])
}
Add(ArraySort,16038886,378,168)
{
ArrayType=2
link(onEndSort,349526:doSort,[])
link(Array,454613:Var1,[(384,159)(370,159)(370,82)])
}
Add(ArraySort,349526,427,168)
{
ArrayType=2
link(Array,3577415:Var3,[(433,159)(461,159)(461,96)])
}
Add(GetDataEx,454613,378,77)
{
link(Data,9808782:Array,[])
}
Add(GetDataEx,3577415,420,91)
{
link(Data,12903765:Array,[])
}
Add(If_else,6738151,287,238)
{
Op2=Integer(1)
link(onTrue,8776206:doEnum,[])
link(onFalse,15241910:doEnum,[(368,251)(368,307)])
link(Op1,893945:X_Y,[(293,166)(160,166)(160,61)(83,61)])
}
Add(MultiStrPart,15346706,168,84)
{
link(onSplit,3603746:doEvent1,[])
}
Add(MathParse,6301918,266,126)
{
MathStr="%1 + %2*1000000"
link(onResult,8511820:doAdd,[])
link(X1,6826135:Var2,[])
link(X2,15638741:Var2,[])
}
Add(MathParse,9401198,504,238)
{
MathStr="round(%1 - %2*1000000,0.001)"
link(onResult,9474807:doString,[])
link(X1,8776206:Item,[(510,229)(430,229)(430,279)(384,279)])
}
Add(Hub,3603746,210,84)
{
link(onEvent1,632349:doCalc,[(291,90)(291,118)])
link(onEvent2,6301918:doCalc,[(233,97)(233,132)])
}
Add(MathParse,632349,322,112)
{
MathStr="%1*1000000 + %2"
link(onResult,8427566:doAdd,[])
link(X1,6826135:Var3,[(328,103)])
link(X2,15638741:Var3,[(335,96)])
}
Add(GetDataEx,6826135,266,98)
{
Angle=3
link(Data,15346706:Part1,[(258,103)(258,138)(174,138)])
}
Add(GetDataEx,15638741,273,91)
{
Angle=3
link(Data,15346706:Part2,[(251,96)(251,124)(181,124)])
}
Add(ArrayEnum,8776206,378,238)
{
link(onItem,3898628:doCalc,[])
link(onEndEnum,10405965:doWork2,[])
link(Array,16038886:ArraySort,[])
}
Add(MathParse,3086401,462,301)
{
DataCount=1
MathStr="round(%1/1000000,0.001)"
link(onResult,12371590:doCalc,[])
}
Add(FormatStr,11472804,567,301)
{
Mask="%1;%2"
link(onFString,3195000:doWork3,[(614,307)])
link(Str2,3086401:Result,[(580,292)(559,292)(559,341)(468,341)])
}
Add(MathParse,12371590,511,301)
{
MathStr="round(%1 - %2*1000000,0.001)"
link(onResult,11472804:doString,[])
link(X1,15241910:Item,[(517,292)(458,292)(458,342)(419,342)])
}
Add(ArrayEnum,15241910,413,301)
{
link(onItem,3086401:doCalc,[])
link(onEndEnum,10405965:doWork3,[(452,314)(452,286)(494,286)])
link(Array,349526:ArraySort,[(419,208)(433,208)])
}
Add(HubEx,3195000,610,238)
{
Angle=3
link(onEvent,893945:onRes,[(614,83)])
}
Add(HubEx,10405965,490,245)
{
Angle=3
link(onEvent,893945:onEnd,[(494,90)])
}
END_SDK
Add(Hub,2314680,357,182)
{
OutCount=4
link(onEvent1,9979027:doWork1,[(382,188)(382,356)])
link(onEvent2,7437200:doClear,[])
link(onEvent3,9067928:doRead,[])
link(onEvent4,9067928:doSort,[])
}
Add(RadioButton,4501545,399,119)
{
Left=130
Top=410
Width=35
Caption="X"
}
Add(RadioButton,4849401,427,119)
{
Left=170
Top=410
Width=35
Selected=0
Caption="Y"
}
Add(MultiElement,16765462,504,245)
{
@Hint=#21:Отрисовка перемещений|
link(onEvent1,6958580:doWork2,[])
link(onEvent2,16331215:doText,[(543,258)(543,293)])
link(Data1,7437200:Strings,[])
link(Data2,10462865:Var1,[(517,236)])
}
BEGIN_SDK
Add(EditMulti,14822359,21,21)
{
EventCount=2
WorkCount=1
DataCount=2
Width=510
Height=326
link(doWork1,4717880:doEvent1,[(60,27)(60,83)])
}
Add(ArrayEnum,4949332,98,91)
{
link(onItem,8145620:doValue,[])
link(onEndEnum,1321641:doEvent1,[(137,104)(137,69)])
link(Array,14822359:Data1,[(104,68)(27,68)])
}
Add(Img_Line,5069216,147,259)
{
Color=32768
Point(Point1)
Point(Point2)
link(Bitmap,14822359:Data2,[(153,250)(34,250)])
link(Point1,14805534:Point,[])
link(Point2,958294:Point,[(167,250)(209,250)])
}
Add(MultiStrPart,16085888,154,140)
{
link(onSplit,720387:doSplit,[])
link(Str,8145620:Value1,[])
}
Add(MemFifo,8145620,154,91)
{
Default=Integer(0)
link(onData,16085888:doSplit,[(193,97)(193,111)(144,111)(144,146)])
}
Add(Hub,4717880,70,77)
{
OutCount=3
link(onEvent1,2979062:doClear,[(242,83)(242,153)])
link(onEvent2,8145620:doClear,[(144,90)(144,104)])
link(onEvent3,4949332:doEnum,[])
}
Add(MultiStrPart,720387,203,140)
{
link(onSplit,2979062:doCalc,[])
link(Str,8145620:Value2,[(209,131)(167,131)])
}
Add(PointXY,14805534,154,210)
{
link(X,10794763:Var2,[])
link(Y,13894762:Var2,[])
}
Add(PointXY,958294,203,210)
{
link(X,2565258:Var2,[])
link(Y,16705406:Var2,[])
}
Add(MathParse,2979062,287,140)
{
DataCount=4
MathStr="%0 + sqrt(sqr(%1 - %3) + sqr(%2 - %4))"
Point(doClear)
link(onResult,5069216:doDraw,[(326,146)(326,272)(137,272)(137,265)])
link(X1,10794763:Var3,[(293,131)(272,131)(272,201)])
link(X2,13894762:Var3,[(300,124)(265,124)(265,194)])
link(X3,2565258:Var3,[(307,117)(258,117)(258,187)])
link(X4,16705406:Var3,[(314,110)(250,110)(250,180)])
}
Add(Hub,1321641,161,63)
{
link(onEvent1,14822359:onEvent1,[(186,69)(186,27)])
link(onEvent2,13377564:doOperation,[(277,76)(277,195)])
}
Add(GetDataEx,10794763,154,196)
{
link(Data,16085888:Part1,[])
}
Add(GetDataEx,13894762,161,189)
{
link(Data,16085888:Part2,[])
}
Add(GetDataEx,2565258,203,182)
{
link(Data,720387:Part1,[])
}
Add(GetDataEx,16705406,210,175)
{
link(Data,720387:Part2,[])
}
Add(FormatStr,10596837,364,189)
{
DataCount=1
Mask="Сумма перемещений %1 пиксель"
link(onFString,14822359:onEvent2,[(405,195)(405,34)])
}
Add(Math,13377564,287,189)
{
OpType=35
Op2=1
link(onResult,10596837:doString,[])
link(Op1,2979062:Result,[])
}
END_SDK
Add(MultiElement,6618759,231,105)
{
@Hint=#15:Случайные точки|
link(onEvent1,13120516:doCreate,[(270,111)(270,83)])
link(onEvent2,1315472:doAdd,[])
link(onEvent3,1315472:doClear,[])
link(onEvent4,13579349:doWork1,[(270,132)(270,188)])
link(Data1,9021511:Text,[])
}
BEGIN_SDK
Add(EditMulti,7359407,21,21)
{
EventCount=4
WorkCount=2
DataCount=1
VOffset=20
HOffset=77
link(doWork1,7711142:doRandomize,[(140,47)(140,83)])
link(doWork2,6444646:doEvent1,[(53,54)(53,62)])
}
Add(For,1119670,91,70)
{
End=100
IncludeEnd=1
link(onEvent,7711142:doRandom,[])
link(onStop,7359407:onEvent4,[(130,83)(130,118)(298,118)(298,68)])
link(End,7359407:Data1,[])
}
Add(Hub,6444646,63,56)
{
OutCount=3
link(onEvent1,7359407:onEvent1,[(148,62)(148,47)])
link(onEvent2,7359407:onEvent3,[(155,69)(155,55)(263,55)(263,61)])
link(onEvent3,1119670:doFor,[])
}
Add(Random,7711142,161,70)
{
Min=5
Max=395
link(onRandom,1108238:doRandom,[])
}
Add(Random,1108238,203,70)
{
Min=5
Max=395
link(onRandom,7131590:doString,[])
}
Add(FormatStr,7131590,252,70)
{
Mask="%1;%2"
link(onFString,7359407:onEvent2,[(291,76)(291,54)])
link(Str1,7711142:Random,[(258,61)(244,61)(244,110)(167,110)])
}
END_SDK
Add(MultiElement,13579349,315,182)
{
@Hint=#15:Отрисовка точек|
link(onEvent1,2314680:doEvent1,[])
link(Data1,5874569:Var2,[])
link(Data2,11396531:Var1,[(328,110)])
}
BEGIN_SDK
Add(EditMulti,16454234,21,21)
{
EventCount=1
WorkCount=1
DataCount=2
Width=216
Height=137
VOffset=21
HOffset=28
link(doWork1,13998334:doEnum,[])
}
Add(ArrayEnum,13998334,49,42)
{
link(onItem,13321758:doSplit,[(88,48)(88,69)])
link(onEndEnum,16454234:onEvent1,[(95,55)(95,48)])
link(Array,16454234:Data1,[])
}
Add(MultiStrPart,13321758,112,63)
{
link(onSplit,2458851:doDraw,[(151,69)(151,83)(95,83)(95,125)])
}
Add(Img_Point,2458851,105,119)
{
Point(X)
Point(Y)
Point(Color)
Point(Size)
link(Bitmap,16454234:Data2,[(111,33)(62,33)])
link(X,13321758:Part1,[])
link(Y,13321758:Part2,[])
link(Color,13934703:Value,[(132,103)(167,103)])
link(Size,14443183:Value,[(139,110)(174,110)])
}
Add(Memory,13934703,161,63)
{
Default=Integer(255)
}
Add(Memory,14443183,168,63)
{
Default=Integer(3)
}
END_SDK
Add(Hub,7398956,441,245)
{
link(onEvent1,16765462:doWork1,[])
link(onEvent2,9979027:doWork3,[(466,258)(466,370)])
}
Add(GetDataEx,5874569,315,168)
{
Angle=3
link(Data,1315472:Strings,[(307,173)])
}
Add(GetDataEx,10462865,560,231)
{
link(Data,11396531:Var3,[(566,110)])
}
Add(Label,16331215,560,287)
{
Left=220
Top=415
Font=[MS Sans Serif,8,1,32768,1]
}
Add(Label,3974761,616,413)
{
Left=570
Top=415
Font=[MS Sans Serif,8,1,16711680,1]
}
Add(Hub,6564702,441,175)
{
link(onEvent1,9979027:doWork2,[(473,181)(473,363)])
link(onEvent2,7437200:doAdd,[])
}
Add(MultiElement,8309979,560,406)
{
@Hint=#21:Отрисовка перемещений|
link(onEvent1,6958580:doWork3,[(599,412)(599,342)(550,342)])
link(onEvent2,3974761:doText,[])
link(Data1,9004184:Strings,[])
link(Data2,10462865:Var3,[(573,236)])
}
BEGIN_SDK
Add(EditMulti,1812893,21,21)
{
EventCount=2
WorkCount=1
DataCount=2
Width=510
Height=326
link(doWork1,14363440:doEvent1,[(60,27)(60,83)])
}
Add(ArrayEnum,256609,98,91)
{
link(onItem,12531990:doValue,[])
link(onEndEnum,9523333:doEvent1,[(137,104)(137,69)])
link(Array,1812893:Data1,[(104,68)(27,68)])
}
Add(Img_Line,10285050,147,259)
{
Color=16711680
Point(Point1)
Point(Point2)
link(Bitmap,1812893:Data2,[(153,250)(34,250)])
link(Point1,10355936:Point,[])
link(Point2,9729824:Point,[(167,250)(209,250)])
}
Add(MultiStrPart,15852750,154,140)
{
link(onSplit,1193268:doSplit,[])
link(Str,12531990:Value1,[])
}
Add(MemFifo,12531990,154,91)
{
Default=Integer(0)
link(onData,15852750:doSplit,[(193,97)(193,111)(144,111)(144,146)])
}
Add(Hub,14363440,70,77)
{
OutCount=3
link(onEvent1,3093968:doClear,[(242,83)(242,153)])
link(onEvent2,12531990:doClear,[(144,90)(144,104)])
link(onEvent3,256609:doEnum,[])
}
Add(MultiStrPart,1193268,203,140)
{
link(onSplit,3093968:doCalc,[])
link(Str,12531990:Value2,[(209,131)(167,131)])
}
Add(PointXY,10355936,154,210)
{
link(X,9489505:Var2,[])
link(Y,10114901:Var2,[])
}
Add(PointXY,9729824,203,210)
{
link(X,7814221:Var2,[])
link(Y,10251303:Var2,[])
}
Add(MathParse,3093968,287,140)
{
DataCount=4
MathStr="%0 + sqrt(sqr(%1 - %3) + sqr(%2 - %4))"
Point(doClear)
link(onResult,10285050:doDraw,[(326,146)(326,272)(137,272)(137,265)])
link(X1,9489505:Var3,[(293,131)(272,131)(272,201)])
link(X2,10114901:Var3,[(300,124)(265,124)(265,194)])
link(X3,7814221:Var3,[(307,117)(258,117)(258,187)])
link(X4,10251303:Var3,[(314,110)(250,110)(250,180)])
}
Add(Hub,9523333,161,63)
{
link(onEvent1,1812893:onEvent1,[(186,69)(186,27)])
link(onEvent2,13392276:doOperation,[(277,76)(277,195)])
}
Add(GetDataEx,9489505,154,196)
{
link(Data,15852750:Part1,[])
}
Add(GetDataEx,10114901,161,189)
{
link(Data,15852750:Part2,[])
}
Add(GetDataEx,7814221,203,182)
{
link(Data,1193268:Part1,[])
}
Add(GetDataEx,10251303,210,175)
{
link(Data,1193268:Part2,[])
}
Add(FormatStr,16514686,364,189)
{
DataCount=1
Mask="Сумма перемещений %1 пиксель"
link(onFString,1812893:onEvent2,[(405,195)(405,34)])
}
Add(Math,13392276,287,189)
{
OpType=35
Op2=1
link(onResult,16514686:doString,[])
link(Op1,3093968:Result,[])
}
END_SDK
Add(HubEx,6958580,546,245)
{
link(onEvent,15117092:doLoad,[])
}
Add(StringTable,9004184,546,350)
{
Left=675
Top=5
Width=125
Height=400
Color=16711680
Font=[MS Sans Serif,8,1,32768,1]
Columns=#4:X=50|4:Y=50|
Grid=0
Point(Strings)
}
Add(MultiElement,9979027,490,350)
{
@Hint=#23:Оптимизация перемещений|
link(onEvent1,9004184:doAdd,[])
link(onEvent2,9004184:doClear,[])
link(onEvent3,8309979:doWork1,[(536,370)(536,412)])
}
BEGIN_SDK
Add(EditMulti,6292303,21,21)
{
EventCount=3
WorkCount=3
Width=671
Height=277
link(doWork1,1370328:doClear,[(53,27)(53,76)])
link(doWork2,1370328:doAdd,[(123,34)(123,69)])
link(doWork3,10257272:doFor,[(46,41)(46,167)])
}
Add(For,10257272,56,161)
{
IncludeEnd=1
link(onEvent,5283545:doEvent1,[])
link(onStop,4276565:doEvent1,[(95,174)(95,251)])
link(End,3092183:Var1,[(69,152)])
}
Add(StrList,1370328,133,63)
{
Point(Idx1)
Point(Idx2)
Point(doSwap)
Point(EndIdx)
link(Idx1,7608661:Value,[(153,47)(623,47)(623,216)(587,216)])
link(Idx2,3108101:Var2,[(160,54)(279,54)])
}
Add(MultiStrPart,10242604,196,168)
{
link(onSplit,9961748:doOperation,[])
}
Add(Math,9961748,238,168)
{
Op2=1
ResultType=0
link(onResult,12039407:doFor,[])
link(Op1,10257272:Position,[(244,159)(188,159)(188,208)(62,208)])
}
Add(For,12039407,287,168)
{
link(onEvent,13989208:doRead,[])
link(onStop,1370328:doSwap,[(326,181)(326,125)(116,125)(116,111)])
link(Start,3108101:Var3,[(293,159)])
link(End,3092183:Var3,[(300,152)])
}
Add(GetDataEx,3092183,154,147)
{
link(Data,1370328:EndIdx,[])
}
Add(ArrayRW,913815,147,168)
{
link(onRead,10242604:doSplit,[])
link(Array,14263856:Var2,[])
}
Add(ArrayRW,13989208,336,168)
{
link(onRead,11141326:doSplit,[])
link(Array,14263856:Var3,[(342,145)])
}
Add(GetDataEx,14263856,147,140)
{
link(Data,1370328:Array,[])
}
Add(MultiStrPart,11141326,385,168)
{
link(onSplit,5264858:doCalc,[])
}
Add(MathParse,5264858,455,168)
{
DataCount=4
MathStr="sqrt(sqr(%1 - %3) + sqr(%2 - %4))"
link(onResult,9845417:doCompare,[])
link(X1,10242604:Part1,[(461,159)(447,159)(447,229)(202,229)])
link(X2,10242604:Part2,[(468,152)(440,152)(440,222)(209,222)])
link(X3,11141326:Part1,[(475,145)(433,145)(433,215)(391,215)])
link(X4,11141326:Part2,[(482,138)(426,138)(426,208)(398,208)])
}
Add(Hub,5283545,105,161)
{
link(onEvent1,819162:doClear,[(130,167)(130,132)])
link(onEvent2,913815:doRead,[])
}
Add(If_else,9845417,497,168)
{
Type=1
link(onTrue,16354435:doEvent1,[])
link(Op2,819162:Value,[])
}
Add(Memory,819162,504,119)
{
Default=Real(99999999)
}
Add(Hub,16354435,539,168)
{
link(onEvent1,819162:doValue,[(564,174)(564,160)(494,160)(494,125)])
link(onEvent2,7608661:doValue,[])
}
Add(Memory,7608661,581,175)
{
Point(Data)
link(Data,12039407:Position,[(587,166)(573,166)(573,236)(293,236)])
}
Add(GetDataEx,3108101,273,154)
{
Angle=2
link(Data,9961748:Result,[(279,208)(244,208)])
}
Add(Hub,4276565,217,245)
{
link(onEvent1,6292303:onEvent2,[(641,251)(641,34)])
link(onEvent2,8515677:doEnum,[])
}
Add(ArrayEnum,8515677,245,252)
{
link(onItem,6292303:onEvent1,[(634,258)(634,27)])
link(onEndEnum,6292303:onEvent3,[(648,265)(648,41)])
link(Array,14263856:Var1,[(251,236)(139,236)(139,145)])
}
END_SDK

карма: 19

0