void NetClient::Packet_SendNow(uint8* packet_contents, uint16 packet_size, net_peer_t peer) { ENetPacket* packet = enet_packet_create(packet_contents, packet_size, ENET_PACKET_FLAG_RELIABLE | ENET_PACKET_FLAG_NO_ALLOCATE); int result = enet_peer_send(m_enetpeer, 0, packet); enet_host_flush(m_enetclient); // Send packets now so we can reclaim the memory TCheck(result >= 0); }
std::vector<std::vector<int> > TCheck(std::vector<std::vector<int> > cycles, int num_arcs, std::vector<int> len, int order, int &x, std::vector<bool> doub, std::vector<bool> undoub) { std::vector<std::vector<int> > solutions; if (len.size() < num_arcs) { int a = 0; int b = 1; if (doub[len.size()]) {b = 2;} while (a < b) { std::vector<int> temp = len; temp.push_back(a); std::vector<std::vector<int> > out = TCheck(cycles, num_arcs, temp, order, x, doub, undoub); int b = 0; while (b < out.size()) { solutions.push_back(out[b]); b++; }a+=1; } } else { int a = 0; int zero = 0; int one = 0; int three = 0; while (a < cycles.size()) { int sum = cycles[a][0]; int b = 1; while (b < cycles[a].size()) { sum+=len[cycles[a][b]]; b++; } if (sum == 3 || sum == 1) { three++; } if ((sum%2)==0) {zero++;} else if ((sum%2)==1) {one++;} a++; } if ((zero == one || zero+2 == one) && three>= 2) { int sum = 0; a = 0; while (a < len.size()) { sum+=len[a]; a++; } int y = 0; if ((order-sum)%2 == 0) { x++; std::vector<std::vector<int> > out = FCheck(cycles, num_arcs, len, order, 0, y, doub); std::cout << "part " << x << " complete" << std::endl; a = 0; while (a < out.size()) { solutions.push_back(out[a]); a++; } } } } return solutions; }
void NetClient::Service() { m_shared.Service(); uint16 packet_size; // In bytes uint8 packet_contents[MAX_PACKET_LENGTH]; packet_size = 2; packet_contents[0] = 'V'; packet_contents[1] = 0; // How many values are in this packet? for (int n = 0; n < m_shared.m_replicated_fields_size; n++) { replicated_field_t table_entry_index = m_shared.m_replicated_fields[n].m_table_entry; TAssert(table_entry_index < m_shared.m_replicated_fields_table_size); replicated_entity_instance_t entity_instance_index = m_shared.m_replicated_fields[n].m_instance_entry; ReplicatedField* table_entry = &m_shared.m_replicated_fields_table[table_entry_index]; ReplicatedInstanceEntity* entity_instance = &m_shared.m_replicated_entities[entity_instance_index]; if (memcmp(ENTITY_FIELD_OFFSET(entity_instance->m_entity, table_entry->m_offset), ENTITY_FIELD_OFFSET(entity_instance->m_entity_copy, table_entry->m_offset), table_entry->m_size) == 0) continue; m_shared.Packet_WriteValueChange(packet_contents, &packet_size, table_entry_index, entity_instance_index); memcpy(ENTITY_FIELD_OFFSET(entity_instance->m_entity_copy, table_entry->m_offset), ENTITY_FIELD_OFFSET(entity_instance->m_entity, table_entry->m_offset), table_entry->m_size); } if (packet_contents[1]) m_shared.Packet_Send(packet_contents, packet_size, 0); ENetEvent event; while (enet_host_service(m_enetclient, &event, 0) > 0) { switch (event.type) { case ENET_EVENT_TYPE_CONNECT: break; case ENET_EVENT_TYPE_RECEIVE: TCheck(event.packet->dataLength); if (!event.packet->dataLength) break; switch (event.packet->data[0]) { case 'C': { TAssert(event.packet->dataLength == 5); replicated_entity_instance_t entity_instance_index = event.packet->data[1]; replicated_entity_t entity_table_index = event.packet->data[2]; uint16 entity_index = tntohs(*(uint16*)&event.packet->data[3]); AddEntityFromServer(entity_instance_index, entity_table_index, entity_index); break; } case 'V': TAssert(((uint16)event.packet->dataLength) == event.packet->dataLength); m_shared.Packet_ReadValueChanges(event.packet->data, (uint16)event.packet->dataLength); break; case 'W': TAssert(event.packet->dataLength == 2); m_peer_index = event.packet->data[1]; break; default: TUnimplemented(); break; } enet_packet_destroy(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: TUnimplemented(); break; default: TUnimplemented(); break; } } }
std::string run (std::vector<int> edges, std::string end, std::fstream &file2) { std::cout << "\n" << "begin graph" << std::endl; std::string out; Graph g; int a = 0; edge e2; vertex_t last = -1; while (a < edges.size()) { e2.v1 = edges[a]; e2.v2 = edges[a+1]; g.edges.push_back(e2); if (edges[a] > last) { last = edges[a]; } if (edges[a+1] > last) { last = edges[a+1]; } a++; a++; } int move = 0; while (move < g.edges.size()) { g.edges[move].chordCheck(last); move++; } out+="EDGES IN THE GRAPH\n\n"; g.write(out, file2); // List all the edges in the graph out+="\n"; g.writeChords(out, file2); std::vector< std::vector<vertex_t> > listOfCycles; // Create a vector that contains the list of all cycles in G. listOfCycles = g.findAllCycles(); // find all the cycles std::vector< int > lengthlist; for (auto i: listOfCycles){ lengthlist.push_back(i.size()); } std::sort(lengthlist.begin(), lengthlist.end()); std::vector<bool> doub = g.degree(last); std::vector<bool> undoub = g.degree2(last); std::string alpha = "abcdefghijklmnopqrstuvwxyz"; a = 0; int num_red = 0; std::vector<std::vector<int> > formula; out+="Cycle Equations:\n"; while (a < listOfCycles.size()) { std::vector<int> cycle; cycle.push_back(0); out+="cycle "; out+=change(a); out+=": "; int b = 0; int ChordCount = 0; int ArcCount = 0; while (b < listOfCycles[a].size()-1) { int c = 0; while (c < g.edges.size()) { if (g.edges[c].has(listOfCycles[a][b]) && g.edges[c].has(listOfCycles[a][b+1])) { if (g.edges[c].chord) { ChordCount++; cycle[0]++; } else { if (doub[c]) { out+=alpha[c]; out+=" + "; } else { out+=alpha[c]; out+="' + "; } cycle.push_back(c); ArcCount++; } } c++; } b++; } int c = 0; while (c < g.edges.size()) { if (g.edges[c].has(listOfCycles[a][b]) && g.edges[c].has(listOfCycles[a][0])) { if (g.edges[c].chord) { cycle[0]++; ChordCount++; } else { if (doub[c]) { out+=alpha[c]; out+=" + "; cycle.push_back(c); ArcCount++; } else { out+=alpha[c]; out+="' + "; cycle.push_back(c); ArcCount++; } } } c++; } formula.push_back(cycle); out+=change(ChordCount); out+="\n"; a++; } int num_arcs = 0; a = 0; while (a < g.edges.size()) { if (!g.edges[a].chord) { num_arcs++; } a++; } a = 0; while (a < num_arcs) { if (!doub[a]) { num_red++; } a++; } std::vector<int> blank; int keep = 0; if (listOfCycles.size()%2 == 1) { out+="There are an odd number of cycles, cannot be 2-pancyclic"; } else { int order = listOfCycles.size()/2; order = order+2; out+="The order is "; out+=change(order); out+= "\n"; // std::cout << "num cycles " << listOfCycles.size() << " num arcs " << num_arcs << " num red " << num_red << std::endl; std::vector<std::vector<int> > pans = TCheck(formula, num_arcs, blank, order, keep, doub, undoub); a = 0; if (pans.size() > 0) { out+= "This is a 2-pancyclic graph\n"; } else { out+="This is not a 2-pancyclic graph\n"; } while (a < pans.size()) { int b = 0; while (b < pans[a].size()) { out+=alpha[b]; out+=" = "; out+=change(pans[a][b]); out+="\n"; b++; } out+="\n"; a++; } } out+="end graph \n"; out+=end; out+=" "; return out; }