0

这实际上是一个程序,LabVIEW但我可以C在 labview 中编写脚本和/logicLabVIEWC. 也是为了吸引更多的答案。所以我主要只需要算法。请阅读整个问题。

在我的应用程序中,我有 5 个变量说:

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

现在这 5 个变量控制着我应该如何过滤从文件中读取的数据。
因此,为此我有一个 switch case,它将根据这些输入执行操作。

要控制开关,我这样做:

  • 如果 var1 为空,则false.
  • 如果 var2 为空,则为 false。
  • 如果 var3 是一个空数组,那么false.
  • 如果 var4 是一个空数组,那么false.
  • 如果 var5falsetrue.

所以我得到一个 5 位组合,所以我可以有 32 个值,因此有 32 种类型的过滤器,即 32 种情况!

例如,如果var1为空,var2不为空,var3不为空,var4为空,var5为真,那么我有 01101(12 月 13 日)。所以我选择了第 13 个过滤器。

编码这真的很忙,所以我想折叠案例的数量。怎么做?
我正在寻找的是一种算法。

这是labview代码

这是案例控制

var1 -> 操作员姓名,var2-> 主管姓名,var3->JobID,var4-> 多批次选择,var5-> 无效日期。

编辑。; 例如
,如果 var1 和 var3 不为空,那么我必须从文件中读取数据,使其包含 var1 和 var2 数据。

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.

4

1 回答 1

1

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).

于 2013-05-30T03:15:38.957 回答