Home > Mateda2.0 > functions > ising-model > LoadIsing.m

LoadIsing

PURPOSE ^

[lattice, inter] = LoadIsing(n, inst)

SYNOPSIS ^

function [lattice, inter] = LoadIsing(n, inst)

DESCRIPTION ^

 [lattice, inter] = LoadIsing(n, inst)
 LoadIsing: Reads  the file of an Ising instance 
 INPUT
 n: number of variables
 inst: the number of the instance
 OUTPUT
 Isinglattice: this structure represents the J matrix (The neighboors for each node)
 Isinginter: this structure contains the value of the interactions between spins

 Last version 8/26/2008. Carlos Echegoyen and Roberto Santana (roberto.santana@ehu.es)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [lattice, inter] = LoadIsing(n, inst)
0002 % [lattice, inter] = LoadIsing(n, inst)
0003 % LoadIsing: Reads  the file of an Ising instance
0004 % INPUT
0005 % n: number of variables
0006 % inst: the number of the instance
0007 % OUTPUT
0008 % Isinglattice: this structure represents the J matrix (The neighboors for each node)
0009 % Isinginter: this structure contains the value of the interactions between spins
0010 %
0011 % Last version 8/26/2008. Carlos Echegoyen and Roberto Santana (roberto.santana@ehu.es)
0012 
0013 
0014 %instance = ['./IsingInstances/SG_', num2str(n), '_', num2str(inst), '.txt'];
0015 instance = ['SG_', num2str(n), '_', num2str(inst), '.txt'];
0016 
0017 fp = fopen(instance, 'r');
0018 numVars = fscanf(fp, '%d', 1);
0019 dim = fscanf(fp, '%d', 1);
0020 neigh = fscanf(fp, '%d', 1);
0021 width = fscanf(fp, '%d', 1);
0022 
0023 % Initialize laticce and inter
0024 neighbor = power(2, neigh) * dim;
0025 lattice = zeros(numVars, neighbor + 1);
0026 inter = zeros(numVars, neighbor);
0027 
0028 % Load the structures from file
0029 for i=1:numVars
0030     lattice(i,1) = fscanf(fp, '%d', 1);
0031     
0032     if lattice(i,1) > 0
0033     
0034         for j=2:lattice(i,1) + 1
0035             lattice(i,j) = fscanf(fp, '%d', 1) + 1;
0036         end
0037     
0038         for j=1:lattice(i,1)
0039             inter(i,j) = fscanf(fp, '%d', 1);
0040         end
0041 
0042     end
0043     
0044 end
0045 
0046 fclose(fp);

Generated on Fri 04-Dec-2009 13:38:29 by m2html © 2003