0
votes

This is actually a program in LabVIEW but I can write C scripts in labview and /or simulate the same logic in LabVIEW as in C. also to attract more answers. So I just need the algorithm mainly. Please read the entire question.

In my application I have 5 variables say:

var1 -> type string,
var2 -> type string,
var3 -> type array of strings,
var4 -> type array of strings,
var5 -> type boolean 

Now these 5 variables control how I should filter the data I read from a file.
So for this I have a switch case which will do the actions based on these inputs.

To control the switch I do this:

  • if var1 is empty then false.
  • if var2 is empty then false.
  • if var3 is an empty array then false.
  • if var4 is an empty array then false.
  • if var5 false of true.

So I get a 5 bit combination so I can have 32 values, hence 32 types of filters i.e 32 cases!.

For e.g if var1 is empty, var2 is not empty, var3 is not empty, var4 is empty, var5 is true then I have 01101 (13 in dec). So I choose the 13th filter.

Coding this is really hectic so I want to collapse the number of cases. How to do it?
What i'm looking for is an algorithm.

here is the labview code

This is the case conrol

var1 -> operator name, var2->supervisor name, var3->JobID, var4-> Multiple batch select, var5->invalid date.

EDIT. ; an e.g
if var1 and var3 are not null then i have to read the data from file such that it contains var1 and var2 data.

e.g 2
now if var1, var3, var5 are not null then i need to select data such that it will have data common to var1 and var3 and var5.

e.g 3
if i have var1,var3,var4,var5 i need to fetch data that containds data which is common to var1 var3 var4 var5.

e.g4
if i have just var3 i need to fetch only data related to var3.

1
not sure what you are asking. You still need to handle 32 different cases, and need to code them. Unless you have some logic in which there is no dependency between the variable then you only need to code 10 cases (5 variable , each can be true/false)Mzf
@Mzf i'm unfortunately coding all those but i'm afraid that in future if the no of variables increase then its will be logarithmic increase in the no of cases. one more variable and i have to code 64 cases! its impractical. the 5 variables filter how much content i have to read from the file :(Koushik Shetty
logarithmic increase is not good .... Again - if there is no dependency between the variables, it's linear increasingMzf
The filter is dependant on all these variables and they have same priority. if only var1 and var2 are present then i have to filter data such that only that containing var1 and var2 are read. if var1,var2 and var3 are present then i have to filter even more.Koushik Shetty
I have added answer that I think can help you , check itMzf

1 Answers

1
votes

There are a number of possibilities to do what you're asking/suggestions for improvement.

  1. For each test you do, have a nested Case structure. A recommendation here: if you have certain tests that are more likely to fail, put them on the outside. That way you can optimize execution.

  2. The Case structure you already have can handle multiple cases by using ranges. For example, you can handle the numbers 1 through 10 by typing 1..10 in the Case Selector box. You might be able to reduce the number of cases by making certain cases consecutive.

  3. I'm not exactly sure which version of LabVIEW you're using, but some of the tests you're doing can be simplified a bit. For example, I believe in LabVIEW 2011 and later, there are special test-for-empty-array and test-for-empty-string functions that you can use.

  4. Also, instead of using 5 Insert Into Array functions, try a single Build Array function that's expanded to hold the number of booleans you have.

I think "exponential increase" is the type of increase meant here, if you have more booleans. The number of cases (theoretically) is 2^(number of variables).