We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
prHi
I'm new to this site and first of all i would like to thank all for this forum, he can be important to help each other.
My problem
I have a c algorithm and i ould like to put this in my adin, i don't know to do it.
this is the algorithm
/* METODO SIMPLEX */
#include <stdlib.h> #include <antashev.h> #include <bntashev.h> #include <cntashev.h>
//Lo maximo que pueden alcanzar las variables y restricciones #define MAX 10 #define RESTRICCION 3 double funcion[MAX], restricciones[MAX+1][MAX+RESTRICCION]; double independiente[RESTRICCION]; int leeDatos(int *var) { int rest,c,i;
prin(" Funcion a Optimizar \nNumero de Variables: "); scan("%d",var); prin("\nRecuerda: c1.X1+c2.X2+...cn.Xn = b \n\n"); for(c=0;c<*var;c++){ prin(" c%d: ", c+1); scan("%lf",&funcion[c]); ffflush(); } prin("\nNumero de Restricciones: "); scan("%d",&rest); ffflush(); for(i=0;i<rest;i++){ prin("Restriccion %d\n",i+1); for(c=0;c<*var;c++){ prin(" c%d: ",c+1); scan("%lf",&restricciones[i][c]); ffflush(); } prin("Termino independiente "); scan("%lf", &independiente[i]); ffflush(); }
return rest; }
int main(void){ int rest, var, ni ; int i,j, k, columna, renglon, count, cuenta; double maximo = 0, menor, aux, mult, temp; rest = leeDatos(&var);
//Crear tabla inicial simplex for(i=0;i<rest;i++) for(j=0; j<rest; j++) if (i == j) restricciones[i][var+j]=1; else restricciones[i][var+j]=0; for(i=0; i<rest;i++) restricciones[i][var+rest] = independiente[i];
for(j=0; j<var; j++) restricciones[rest][j] = funcion[j] * -1; for(j=var; j<rest+var; j++) restricciones[rest][j] = 0;
ni=1; prin("\n-----------------------------------------------"); prin("\n ITERACION %d",ni); prin("\n-----------------------------------------------\n"); ni+++; for(i=0; i<=rest; i++) { for(j=0; j<=rest+var; j++) prin(" %.2lf \t", restricciones[i][j]); prin("\n"); }
//Encontrar la variable de decision que entra a la base //y la de holgura que saldra de la base
do { //Encontrar la variable de decision que entrara a la base maximo = abs(restricciones[rest]); columna = 0; for(j=0; j<=rest+var; j++) { if( restricciones[rest][j] < 0 ) { temp = -1 * restricciones[rest][j]; if ( maximo < temp) { maximo = temp; columna = j; } } else continue; else stop(); }
count = 0; aux = 1e20; menor = 1e20; for(i=0; i<rest; i++) {
if(restricciones[i][columna] > 0) aux = restricciones[i][rest+var] / restricciones[i][columna]; else count++; if( menor > aux ) { menor = aux; renglon = i; } } if(count == rest) { prin("Soluci� no acotada"); andinexit(); } prin("\nPivote: %.2lf, renglon %d columna %d",restricciones[renglon][columna], renglon, columna);
//Encontrar los coeficientes de la nueva tabla aux = restricciones[renglon][columna]; for(j=0; j<=(rest+var); j++) restricciones[renglon][j] = restricciones[renglon][j] / aux;
for(i=0; i<=rest; i++) { if (i == renglon ) continue; else { aux = restricciones[i][columna] * -1; for(k=0; k <= rest+var; k++) { restricciones[i][k] = (aux * restricciones[renglon][k]) + restricciones[i][k]; } }
} prin("\n-----------------------------------------------"); prin("\n ITERACION %d",ni); prin("\n-----------------------------------------------\n"); ni++; for(i=0; i<=rest; i++) { for(j=0; j<=rest+var; j++) prin(" %.2lf \t", restricciones[i][j]); prin("\n"); } cuenta = 0; for(j=0;j<rest+var;j++) if(restricciones[rest][j] >= 0) cuenta++; if (cuenta == rest+var) break; } while(cuenta);
prin("---->");
}
Any help??
Thanks
1) Why not format the code according to the posting instructions?
2) Is a variable named "var" given a descriptive name?
3) What is scan()? A spelling error for scanf()? How do you know that your scan() does always produce the correct number of parameters - maybe the user jus presses enter without giving any values?
4) What is prin("xx")? A spelling error of printf()?
5) What is stop()?
6) What is andinexit()?
7) What is "adin"? A register containing ADC conversion values or something else? You didn't really spend much time explaining what you want help with.