ATTENTIONThis 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 |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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) | ||
|
#4
|
||||
|
||||
|
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;
}
}
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]);
}
}
Brandon
__________________
thats not normal.
|
| The Following 2 Users Say Thank You to Brandon Peterson For This Useful Post: | ||
Scott Mackay (03-08-2011) | ||
|
#5
|
||||
|
||||
|
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 |