Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Find nearest value

Hello

I want to create in my model Warehouse with different parts (different length), then if I need part with lenght = 0.55 then Crane will take closest (value upward). From which commands should I use?

Another question is, if I have in Frame another Frame1, can I take  part from Frame1 using Crane?

And the last, is it possible to create something as a home page. When I open my model I want have option to eneter the parameters or load from excel.

Regards

8 REPLIES

Re: Find nearest value

here you need to program a "search" method to return the right object; to get the part you can use the method moveToObject + moveHook (see help)

it would be helpful to record the length of the part, if you store them. Then you can calculate the differences and search the min-difference.. The tablefile offers some stuff for calculations (e.g. min).

 

You cannot place objects for the crane in sub-frames. The crane uses the positions of the objects to create the movements. The subframe has only one x,y coordinate for the crane.


Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: Find nearest value

I gave the table (name: need) with required length. When method will find required part remove it from Store, and delete information from table need. So if I have in Store 2 the same parts it will take only one.

But now I dont know how to take from Store with nearest value.
It should take different between in this moment needed length and the length of the checking element.
But if I have diffenet and I take min value, there may be negative value.
Any advice what should I do?

Regards

 

Re: Find nearest value

first:
your method_in should only register the parts; if you use in the first column type object instead of string, you can store a link to the object itself into the table (@). This you can use to move the MU from the store.

In your method_out you need to calculate the difference (set a failure value for negative values e.g. 99999) for each row in storeList, then you can use the method storeList.min (see help) to search for the lowest value; Plant Simulation moves the cursor to this position, so you can access the part with
storeList[1,storeList.yDim]

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: Find nearest value

So in method_in I take information about object, now in method_out I dont know what I shoud write.
I calculate different between @.MUlength and need, then I take value 1000 when different is < 0.
But this is in method_in, when I have more values in table need it is wrong.
from which the command should start method_out?

Regards

Solution
Solution
Accepted by topic author Lucas
‎09-29-2016 03:11 PM

Re: Find nearest value

[ Edited ]

in your second model you are on a good way. method_out is called by the generator.

At the start you should exit the method if there are no parts in the store and if the out buffer is occupied.

Then you calculate for all parts in the store the difference.

In the next step you calculate the minimum and move one part (if there is one).

This could look like this:

is
	i:integer;
	dif:real;
	part:object;
	minL:real;
		
do
	if out.occupied or store.empty then
		return;
	end;
	--calculate differences
	for i:=1 to storeList.yDim loop
		
		dif:=storeList[1,i].MUlength-need[1,need.position];
		if dif <= 0 then
			dif:= 1000;
		end;
		storeList[5,i]:=dif;		
			
	next;
	--look for the minimum
	minL:=storeList.min({5,1}..{5,*});
	--if all parts are too short --> min= 1000
	if minL <1000 then --
		part:=storeList[1,storeList.cursorY];
		part.move(out);
		StoreList.cutRow(StoreList.cursorY);
	
		--increase position ???
	else
		debug; --all parts are too short
	end;
	
end;

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net


Re: Find nearest value

This is it what I need, thank you very much.

Re: Find nearest value

Hello,

I have one question to this model, What command I should write if I need element with nearest value (as in this method) and extra element Hieght is equal to 0.2? I cant write @.MUheight, it must be condition like:

if minL <1000 and HEIGHT = value from table


BR
Lucas

Solution
Solution
Accepted by topic author Lucas
‎01-07-2017 07:38 AM

Re: Find nearest value

in the solution I mark parts that are too short with a failure value 1000. This you should expand to get the right parts with the right height:

 

is
	i:integer;
	dif:real;
	part:object;
	minL:real;
		
do
	if out.occupied or store.empty then
		return;
	end;
	--calculate differences
	for i:=1 to storeList.yDim loop
		
		dif:=storeList[1,i].MUlength-need[1,need.position];
		if dif <= 0 or storeList[1,i].MUHeight /= 0.2 then
			dif:= 1000;
		end;
		storeList[5,i]:=dif;		
			
	next;
	--look for the minimum
	minL:=storeList.min({5,1}..{5,*});
	--if all parts are too short --> min= 1000
	if minL <1000 then --
		part:=storeList[1,storeList.cursorY];
		part.move(out);
		StoreList.cutRow(StoreList.cursorY);
	
		--increase position ???
	else
		debug; --all parts are too short
	end;
	
end;

Steffen Bangsow
freelance simulation specialist  
web: www.bangsow.eu
mail: steffen@bangsow.net