Skip to content

Commit

Permalink
- fixed coding style.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13322 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Oct 11, 2012
1 parent 0310a08 commit 4e6debd
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -764,57 +764,57 @@ double GreaterEq(double a, double b)
/*used in generated code in mixed equatin system to generate next combination of bools*/
/*e.g. for n = 3 generates sequence: 000, 100, 010, 001, 110, 101, 011, 111 */
modelica_boolean nextVar(modelica_boolean *b, int n) {
/*number of "1" */
int n1 = 0;
int i;
for (i = 0; i < n; i++){
if (b[i] == 1)
n1++;
}
/*index of last element with "1"*/
int last = n - 1;
while (last >= 0 && !b[last])
last--;
if (n1 == n) //exit - all combination were already generated
return 0;
else if (last == -1) { /* 0000 -> 1000 */
b[0] = 1;
return 1;
} else if (last < n - 1) { /* e.g. 1010 -> 1001 */
b[last] = 0;
b[last + 1] = 1;
return 1;
} else { /*at the end of the array is "1"*/
/*detect position of last ocurenc of sequence 10 */
int ip = n - 2; //actual position in array
int nr1 = 1; //count of "1"
while (ip >= 0) {
if (b[ip] && !b[ip + 1]) { //we found
nr1++;
break;
} else if (b[ip]) { //we didn't find, but 1 - increase nr1
nr1++;
ip--;
} else { //we didnt't find, 0
ip--;
}
}
if (ip >= 0) { //e.g. 1001 -> 0110
int pn = ip + nr1;
b[ip] = 0;
for (i = ip + 1; i <= pn; i++)
b[i] = 1;
for (i = pn + 1; i <= n - 1; i++)
b[i] = 0;
return 1;
} else {
for (i = 0; i <= n1; i++)
b[i] = 1;
for (i = n1 + 1; i <= n - 1; i++)
b[i] = 0;
return 1;
}
}
/*number of "1" */
int n1 = 0;
int i;
for (i = 0; i < n; i++){
if (b[i] == 1)
n1++;
}
/*index of last element with "1"*/
int last = n - 1;
while (last >= 0 && !b[last])
last--;
if (n1 == n) //exit - all combination were already generated
return 0;
else if (last == -1) { /* 0000 -> 1000 */
b[0] = 1;
return 1;
} else if (last < n - 1) { /* e.g. 1010 -> 1001 */
b[last] = 0;
b[last + 1] = 1;
return 1;
} else { /*at the end of the array is "1"*/
/*detect position of last ocurenc of sequence 10 */
int ip = n - 2; //actual position in array
int nr1 = 1; //count of "1"
while (ip >= 0) {
if (b[ip] && !b[ip + 1]) { //we found
nr1++;
break;
} else if (b[ip]) { //we didn't find, but 1 - increase nr1
nr1++;
ip--;
} else { //we didnt't find, 0
ip--;
}
}
if (ip >= 0) { //e.g. 1001 -> 0110
int pn = ip + nr1;
b[ip] = 0;
for (i = ip + 1; i <= pn; i++)
b[i] = 1;
for (i = pn + 1; i <= n - 1; i++)
b[i] = 0;
return 1;
} else {
for (i = 0; i <= n1; i++)
b[i] = 1;
for (i = n1 + 1; i <= n - 1; i++)
b[i] = 0;
return 1;
}
}
}


0 comments on commit 4e6debd

Please sign in to comment.