miércoles, 1 de diciembre de 2010

Ordenar un hash de pares

$pair{$nfile+1} = [($n,$m)];


my @lpair = sort { ssPair($pair{$a},$pair{$b}) } keys %pair;

for(@lpair){
my $ref = $pair{$_};
my @a = @$ref;
print "'m = $a[1] n = $a[0]',\n";
$ref = $allcost{$_};
my @v = @$ref;
for(@v){
print $output "$_\n"
}
}


sub sPair{

my $ref1 = shift;
my $ref2 = shift;
my @aa = @$ref1;
my @bb = @$ref2;

if($aa[0] < $bb[0]){
return -1;
}
elsif($aa[0] == $bb[0] and $aa[1] < $bb[1]){
return -1;
}
elsif($aa[0] == $bb[0] and $aa[1] > $bb[1]){
return 1;
}
elsif($aa[0] == $bb[0] and $aa[1] == $bb[1])
{
return 0;
}
return 1;
}

martes, 23 de noviembre de 2010

UPC y ACM

La upc por fin ha creado un capítulo de estudiantes de la ACM. A los que se hagan miembros tendrán acceso a las publicaciones. Aquí teneis el link:

http://acm.ac.upc.edu/staff

jueves, 29 de julio de 2010

Fichero opciones CPLEX

file opt / cplex.opt /;
put opt;
put 'iis no';
put /;
*obliga a gams a utilizar el disco duro para los nodos
put 'nodefileind 2';
put /;
*tolerancia de las infactibilidad
put 'eprhs 1e-04';
put /;
*metodo de resolución automático
put 'lpmethod 0';
put /;
putclose opt;
*Para que te coja el fichero
Modelo.OptFile = 1;

sábado, 17 de julio de 2010

Generar numeros aleatorios en gams

Scalar
cc;

execute_load 'seed',cc=cc;
execseed=cc;
seq(reg) = uniformint(1,100);
cc = execseed;
execute_load 'seed',cc;


El número pseudo-aleatorio se usa como semilla para la siguiente vez qeu se ejecute el programa

Implementación de un backtracking Variaciones sin repetición

void variac(int n, int m, int j, vector& used, vector& seq)
{
if(j == m){
for(unsigned int i=0;i cout << seq[i] + 1<<",";
cout << endl;
}
else{

for(int i=0;i if(!used[i]){
used[i] = true;
seq[j] = i;
variac(n,m,j+1,used,seq);
used[i] = false;
}
}
}
}

int main(){

int n = 5;
int m = 2;
for(int i=0;i used.push_back(false);


for(int i=0;i seq.push_back(0);

variac(n,m,0,used,seq);
}