Changeset 739 for cpp/frams/_demos
- Timestamp:
- 02/18/18 02:54:36 (7 years ago)
- Location:
- cpp/frams/_demos
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/genoconv_test.cpp
r732 r739 116 116 } 117 117 118 static int goodWidthForFormat(int genotype_format) 119 { 120 return genotype_format == '0' ? 45 : 15; // more space for long f0 lines 121 } 122 118 123 // arguments: 119 124 // genotype (or - meaning "read from stdin") [default: X] … … 182 187 printf("Conversion map:\n"); 183 188 m.print(); 184 printConvMap(g1.getGenes(), g2.getGenes(), m );189 printConvMap(g1.getGenes(), g2.getGenes(), m, goodWidthForFormat(g1.getFormat())); 185 190 printf("Reverse conversion map:\n"); 186 191 MultiMap rm; 187 192 rm.addReversed(m); 188 193 rm.print(); 189 printConvMap(g2.getGenes(), g1.getGenes(), rm );194 printConvMap(g2.getGenes(), g1.getGenes(), rm, goodWidthForFormat(g2.getFormat())); 190 195 } 191 196 192 197 Model mod1(g1, 1); 193 198 printf("\nModel map for f%c genotype:\n", g1.getFormat()); 194 printModelMap(g1.getGenes(), mod1.getMap()); 199 ModelDisplayMap dm1(mod1); 200 dm1.print(goodWidthForFormat(g1.getFormat())); 195 201 MultiMap mod1combined; 196 mod1combined.addCombined(mod1.getMap(), getModelDisplayMap());202 mod1combined.addCombined(mod1.getMap(), dm1.getMap()); 197 203 mod1combined.print(); 198 204 Model mod2(g2, 1); 199 205 printf("\nModel map for f%c genotype:\n", g2.getFormat()); 200 printModelMap(g2.getGenes(), mod2.getMap()); 206 ModelDisplayMap dm2(mod2); 207 dm2.print(goodWidthForFormat(g2.getFormat())); 201 208 MultiMap mod2combined; 202 mod2combined.addCombined(mod2.getMap(), getModelDisplayMap());209 mod2combined.addCombined(mod2.getMap(), dm2.getMap()); 203 210 mod2combined.print(); 204 211 } -
cpp/frams/_demos/printconvmap.cpp
r732 r739 5 5 #include "printconvmap.h" 6 6 #include <stdio.h> 7 #include <frams/util/multimap.h>8 #include <frams/model/model.h>9 10 #define GEN1MAX 1511 7 12 8 void printN(const char* t, int maxlen) … … 22 18 } 23 19 24 void printmapping(const char* gen1, int len1, const MultiRange &mr, const char* gen2, int len2 )20 void printmapping(const char* gen1, int len1, const MultiRange &mr, const char* gen2, int len2, int left_column_padding) 25 21 { 26 printN(' ', GEN1MAX- len1);22 printN(' ', left_column_padding - len1); 27 23 printN(gen1, len1); 28 24 printf(" : "); … … 43 39 } 44 40 45 void printConvMap(const SString& gen1, const SString& gen2, const MultiMap& map )41 void printConvMap(const SString& gen1, const SString& gen2, const MultiMap& map, int left_column_padding) 46 42 { 47 43 int y, y2, len1; … … 61 57 MultiRange *mr; 62 58 MultiRange emptyrange; 63 printN(' ', GEN1MAX);59 printN(' ', left_column_padding); 64 60 printf(" %s\n", g2.c_str()); 65 61 int begin = map.getBegin(); … … 82 78 y2 = map.getMapping(id + 1)->begin; 83 79 } 84 if ((y2 - y) > GEN1MAX) y2 = y + GEN1MAX;80 if ((y2 - y) > left_column_padding) y2 = y + left_column_padding; 85 81 if (y2 > (y + len1)) y2 = y + len1; 86 printmapping(g + y, y2 - y, *mr, g2.c_str(), g2.len() );82 printmapping(g + y, y2 - y, *mr, g2.c_str(), g2.len(), left_column_padding); 87 83 y = y2; 88 84 } 89 85 } 90 86 91 const MultiMap & getModelDisplayMap() 87 ModelDisplayMap::ModelDisplayMap(Model &m) 88 :model(m) 92 89 { 93 static MultiMap display_map; 94 if (display_map.isEmpty()) 95 { 96 for (int i = 0; i < 10; i++) 97 { 98 display_map.add(Model::partToMap(i), Model::partToMap(i), i, i); 99 display_map.add(Model::jointToMap(i), Model::jointToMap(i), 10 + i, 10 + i); 100 display_map.add(Model::neuroToMap(i), Model::neuroToMap(i), 20 + i, 20 + i); 101 } 102 } 103 return display_map; 90 joint_offset = max(10, (int(9 + model.getPartCount()) / 10) * 10); 91 neuron_offset = joint_offset + max(10, (int(9 + model.getJointCount()) / 10) * 10); 92 max_element = neuron_offset + max(10, (int(9 + model.getNeuroCount()) / 10) * 10); 93 for (int i = 0; i < model.getPartCount(); i++) 94 map.add(Model::partToMap(i), Model::partToMap(i), i, i); 95 for (int i = 0; i < model.getJointCount(); i++) 96 map.add(Model::jointToMap(i), Model::jointToMap(i), joint_offset + i, joint_offset + i); 97 for (int i = 0; i < model.getNeuroCount(); i++) 98 map.add(Model::neuroToMap(i), Model::neuroToMap(i), neuron_offset + i, neuron_offset + i); 104 99 } 105 100 106 void printModelMap(const SString& gen1, const MultiMap& map)101 void ModelDisplayMap::print(int left_column_padding) 107 102 { 108 103 MultiMap combined_map; 109 combined_map.addCombined(map, getModelDisplayMap()); 110 SString g2("012345678901234567890123456789"); 111 printN(' ', GEN1MAX); 112 printf(" Parts Joints Neurons\n"); 113 printConvMap(gen1, g2, combined_map); 104 combined_map.addCombined(model.getMap(), getMap()); 105 static const SString t09("0123456789"); 106 SString g; 107 for (int i = 0; i < max_element; i += 10) 108 g += t09; 109 printN(' ', left_column_padding); 110 printf(" Parts "); 111 printN(' ', joint_offset - 10); 112 printf("Joints "); 113 printN(' ', (neuron_offset - joint_offset) - 10); 114 printf("Neurons\n"); 115 printConvMap(model.getGeno().getGenes(), g, combined_map, left_column_padding); 114 116 } -
cpp/frams/_demos/printconvmap.h
r732 r739 7 7 8 8 #include <frams/util/sstring.h> 9 #include <frams/model/model.h> 10 #include <frams/util/multimap.h> 9 11 10 12 class MultiMap; 11 13 12 void printConvMap(const SString& gen1, const SString& gen2, const MultiMap& map); 13 void printModelMap(const SString& gen1, const MultiMap& map); //automaticaly combines the map with the ModelDisplayMap 14 const MultiMap & getModelDisplayMap(); // mapping: true model -> display (so the regular map printing/debugging tools can be used for model maps, avoiding invonveniently huge numbers) 14 void printConvMap(const SString& gen1, const SString& gen2, const MultiMap& map, int left_column_padding = 15); 15 16 class ModelDisplayMap 17 { 18 MultiMap map; 19 Model &model; 20 int joint_offset, neuron_offset, max_element; 21 public: 22 ModelDisplayMap(Model &m); 23 void print(int left_column_padding = 15); 24 const MultiMap & getMap() { return map; } //mapping: true model -> display (so the regular map printing/debugging tools can be used for model maps, avoiding invonveniently huge numbers) 25 }; 15 26 16 27 #endif
Note: See TracChangeset
for help on using the changeset viewer.