# Min function implementation

648
6
06-03-2014 02:13 AM
New Contributor
Hi everybody,

I would like to to use min function in my .cga file which would assign parameter with the lowest value to an attribute.
Is there any way how to do this?

Thank you

Mary
Tags (3)
1 Solution

Accepted Solutions
Frequent Contributor
hi ..

I had one implementation, then one of the devs helped to simplify the code:
` attr minA = 3 attr minB = 50 attr minC = 2 attr minD = 12   findMin(valList, index, min) =  case (index < 0): min  else:   case(float(listItem(valList, index)) < min): findMin(valList, index-1, float(listItem(valList, index)))   else:                                        findMin(valList, index-1, min)     findMin(valList) = findMin(valList, listSize(valList)-1, float(listItem(valList, listSize(valList)-1)))  Shape -->  print (findMin(str(minA) + ";" + str(minB) + ";" +  str(minC) + ";" + str(minD) + ";") )`

let me know if this works ..

m.
6 Replies
Frequent Contributor
hi..

please give me an example of what you need.

there's ways to do this, but I need a bit preciser description. ok ? 🙂

matt
New Contributor
Hey Matt,

and thank you. I will try to describe it in more detail:

I am dealing with the visualization of uncertainty of the archaeological buildings. Simply written, the easiest method is to classify each parameter of the building with some uncertainty value (0,1). I am assuming that each parameter can have more possibilities. And each of these possibilities has different uncertainty value. Then the final value for the entire building would be the lowest (minimum) value from the uncertainty values of each parameters. I am trying to calculate the final value interactively as are the attributes changed in inspector.

```@Group("Model options",0) @Order(1) @Range("DoorA","DoorB","DoorC")
attr type_of_door   = "DoorA"

doorUncertainty    =
case "DoorA" : 0.8
case "DoorB" : 0.9
else : 0.7

@Group("Model options",0) @Order(2) @Range("WindowA","WindowB","WindowC")
attr type_of_door   = "WindowA"

windowUncertainty   =
case "WindowA" : 1
case "WindowB" : 0.6
else : 0.9

@Group("Model options",0) @Order(3) @Range("WallColorA","WallColorB","WallColorC")
attr type_of_door   = "WallColorA"

wallColorUncertainty  =
case "WallColorA" : 0.2
case "WallColorB" : 0.5
else : 0.8

```

Here I would need something like this:
```buildingUncertainty = min(doorUncertainty, windowUncertainty, wallColorUncertainty)
```

I hope that my explanation is understandable 🙂

Thank you

Mary
Frequent Contributor
do you need exactly 3 inputs to the min() function or 'n' ?

m.
New Contributor
I need 'n' inputs.. 🙂
Frequent Contributor
hi ..

I had one implementation, then one of the devs helped to simplify the code:
` attr minA = 3 attr minB = 50 attr minC = 2 attr minD = 12   findMin(valList, index, min) =  case (index < 0): min  else:   case(float(listItem(valList, index)) < min): findMin(valList, index-1, float(listItem(valList, index)))   else:                                        findMin(valList, index-1, min)     findMin(valList) = findMin(valList, listSize(valList)-1, float(listItem(valList, listSize(valList)-1)))  Shape -->  print (findMin(str(minA) + ";" + str(minB) + ";" +  str(minC) + ";" + str(minD) + ";") )`

let me know if this works ..

m.
New Contributor
Hi Matt,

It works! :)) Thank you so much for your help! I am so happy. And really, thank you, you are making my thesis a lot easier 🙂

Mary