ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 05-24-2010
Congshi Wang Congshi Wang is offline
Student
 
Join Date: May 2010
Location: Germany
Posts: 58
Downloads: 2
Uploads: 0
Thanks: 48
Thanked 0 Times in 0 Posts
Rep Power: 124
Congshi Wang is on a distinguished road
Default Maximum Value inside an array

Is there a function that gets the maximul value insinde an Array:

For example:

doublearray weights = makearray(3);
fillarray(weights, 3.5, 6.7, 1.4);

max(weights) => returns 6.7
  #2  
Old 05-24-2010
RalfGruber's Avatar
RalfGruber RalfGruber is offline
FlexSim Software Products
 
Join Date: Jul 2007
Location: Orem, UT, USA
Posts: 195
Downloads: 37
Uploads: 0
Thanks: 518
Thanked 294 Times in 124 Posts
Rep Power: 345
RalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to behold
Default

Congshi,

this should give you an idea, how to implement the maximum value search. Make it a user command, if you need it at various locations within your model:

doublearray weights=makearray(5); // DEFINE ARRAY
for (int i=1; i<=5; i ++) // FILL ARRAY WITH RANDOM VALUES
{
weights[
i]=uniform(1,10);
pf(weights[i]);pr(); // PRINT ALL VALUES TO OUTPUT CONSOLE
}
double maxweight=
0; // VARIABLE FOR MAX WEIGHT IN ARRAY
for (int j=1; j<=5; j ++) // LOOK THROUGH ALL ARRAY VALUES
{
if(weights[j]>maxweight)
// CHECK IF ARRAY CVALUE IS LARGER THAN CURRENT MAX VALUE
{
maxweight=weights[j];
// IF SO, SET NEW MAX VALUE TO CURRENT ARRAY VALUE
}
}
pt("Max weight: ");pf(maxweight);pr();pr(); // PRINT MAX FOUND VALUE TO OUTPUT CONSOL
return maxweight; // RETUNR MAX FOUND VALUE

Hope that helps!

Good luck

Ralf
Flexsim Germany
The Following 4 Users Say Thank You to RalfGruber For This Useful Post:
Tom David (05-24-2010)
  #3  
Old 02-28-2011
Nischith Kashyap's Avatar
Nischith Kashyap Nischith Kashyap is offline
Flexsim User
 
Join Date: Nov 2010
Location: Wollongong, Australia
Posts: 51
Downloads: 26
Uploads: 0
Thanks: 19
Thanked 0 Times in 0 Posts
Rep Power: 118
Nischith Kashyap is on a distinguished road
Default Multi dimensional Array

Hello

Is there a command to create a multi dimensional array ??

Thanks
  #4  
Old 03-02-2011
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

Nischith,

No there is no multi dimensional array command in Flexsim.

However, I was told by someone who knows what there talking about, that all arrays are stored in memory the same way as single dimensional arrays and that the only difference between a multi and a single was who was doing the work. Confused yet?

Here is an example of two arrays that are for all intents and purposes exactly the same (C++):

Code:
int rows = 10;
int cols = 5;
double arrayone[rows, cols];
double arraytwo[rows * cols];
int count = 0;
for(int row = 0; row < 10; row++){
  for(int col = 0; col < 5; col++){
    count++;
    arrayone[row, col] = count;
    arraytwo[(row * cols) + col] = count;
  }
}
I hope that this example helps you get the idea I'm trying to portray.

So, what do you care? Here is how I would use an array in Flexscript to hold two dimensional data:

Code:
int rows = 10;
int cols = 5;
intarray test = makearray(rows*cols);
int row;
int col;
int count = 0;
for(row = 1; row <= 10; row++){
  for(col = 1; col <= 5; col++){
    count++;
    test[((row - 1) * cols) + col] = count;
  }
}
for(row = 1; row <= 10; row++){
  for(col = 1; col <= 5; col++){
  	pr(); pd(test[((row - 1) * cols) + col]);
  }
}
I hope that this long winded explanation helps,
Brandon
__________________
thats not normal.
The Following 2 Users Say Thank You to Brandon Peterson For This Useful Post:
Scott Mackay (03-08-2011)
  #5  
Old 03-02-2011
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Along the same lines as Brandon's response, if you want to get really funky, then you can use #defines to make a crazy syntax for multdimentional arrays to use arrayname[ROW 4 COL 7] as the syntax for referencing the array.

The following code shows how this can be done.

Code:
int sizex = 15;
int sizey = 4;
doublearray test = makearray(sizex*sizey);
#define ROW sizey*(
#define COL -1)+
int num = 1;
for(int x=1;x<=sizex;x++)
{
    for(int y=1;y<=sizey;y++)
    {
        test[ROW x COL y] = num;
        num++;
        pt("row: ");pd(x);
        pt(" col: ");pd(y);
        pt(" is: ");
        pd(test[ROW x COL y]);pr();
    }
}
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post:
Steven Hamoen (03-02-2011)


Thread Thread Starter Forum Replies Last Post
What is the maximum output of the model in 10 hours? john mic Q&A 1 05-14-2010 11:57 AM
Can't get value from global array Joe Allen Q&A 7 10-30-2008 09:06 AM
Assign an array to a variable AlanZhang Q&A 6 04-24-2008 01:59 PM
Embedding Videos Inside Your Posts Cliff King Q&A 0 09-19-2007 07:55 PM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.