ElfPSP_ParallelABC
Protein Structure Prediction using Parallel Artificial Bee Colony Optimization
movelem.h
Go to the documentation of this file.
1 #ifndef _MOVELEM_H_
2 #define _MOVELEM_H_
3 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "random.h"
13 
21 typedef unsigned char MovElem;
22 
24 enum _MovUnits {
25  FRONT = 0,
26  LEFT = 1,
27  RIGHT = 2,
28  UP = 3,
29  DOWN = 4,
30 };
31 
32 #ifndef MOVELEM_SOURCE_FILE
33  #define MOVELEM_INLINE inline
34 #else
35  #define MOVELEM_INLINE extern inline
36 #endif
37 
43 MOVELEM_INLINE
44 MovElem MovElem_make(unsigned char bb, unsigned char sc){
45  return (bb << 4) | sc;
46 }
47 
49 MOVELEM_INLINE
51  return MovElem_make(urandom_max(DOWN+1), urandom_max(DOWN+1));
52 }
53 
55 MOVELEM_INLINE
56 unsigned char MovElem_getBB(MovElem elem){
57  return elem >> 4;
58 }
59 
61 MOVELEM_INLINE
62 unsigned char MovElem_getSC(MovElem elem){
63  return elem & 0x0F;
64 }
65 
69 MOVELEM_INLINE
70 unsigned char MovElem_to_number(MovElem elem){
71  unsigned char bb = MovElem_getBB(elem);
72  unsigned char sc = MovElem_getSC(elem);
73  return bb * 5 + sc;
74 }
75 
79 MOVELEM_INLINE
80 MovElem MovElem_from_number(unsigned char num){
81  return MovElem_make(num / 5, num % 5);
82 }
83 
87 MOVELEM_INLINE
88 void MovElem_print(MovElem elem, FILE *fp){
89  static const char chars[] = {'F','L','R','U','D'};
90  unsigned char bb = elem >> 4;
91  unsigned char sc = elem & 0x0F;
92  fprintf(fp, "%c,%c", chars[bb], chars[sc]);
93 }
94 
95 #endif
MOVELEM_INLINE MovElem MovElem_make(unsigned char bb, unsigned char sc)
Creates a MovElem.
Definition: movelem.h:44
_MovUnits
Constants for making MovElem elements.
Definition: movelem.h:24
MOVELEM_INLINE void MovElem_print(MovElem elem, FILE *fp)
Prints a movement in the format "%c,%c", without leading/trailing spaces.
Definition: movelem.h:88
MOVELEM_INLINE unsigned char MovElem_getBB(MovElem elem)
Returns the movement for the backbone (BB) stored in a MovElem.
Definition: movelem.h:56
MOVELEM_INLINE MovElem MovElem_random()
Returns a uniformly random MovElem.
Definition: movelem.h:50
MOVELEM_INLINE unsigned char MovElem_getSC(MovElem elem)
Returns the movement for the side chain (SC) stored in a MovElem.
Definition: movelem.h:62
MOVELEM_INLINE unsigned char MovElem_to_number(MovElem elem)
Convert a MovElem to a number.
Definition: movelem.h:70
RANDOM_INLINE unsigned int urandom_max(unsigned int max)
Returns an unsigned integer within [0,max)
Definition: random.h:24
MOVELEM_INLINE MovElem MovElem_from_number(unsigned char num)
Convert a number to MovElem.
Definition: movelem.h:80
unsigned char MovElem
Type that holds 2 movements, one for the backbone and one for the side chain.
Definition: movelem.h:21
Routines for random number generation.