text:
<file_sep>#include <vector>
#include<iostream>
#include<set>
#include<queue>
#include<string>
#include<cstring>
#include <stdlib.h>     /* atoi */
#include<stack>
#include<ctime>

#include "route.h"
#include "lib_record.h"
#include <stdio.h>

/*---------------------------------------------------------------------------------------------------*/
//你要完成的功能总入口
void search_route(char *topo[5000], int edge_num, char *demand)
{
	const clock_t begin_time = clock();
	//cout<<"Begine time: "<< float(begin_time)<<endl;
	/* A is to record already visited vertex in visit_set
	   B is to record already visited vertex in un_visit_set  */
	/*Assign Id to the source vertex and destination vertex, and build the must visited vertex set S
	and not necessary vistied vertex set  S_*/
	set<Vertex> visit_set,un_visit_set,A,B;
	vector<Vertex> demandArray = ConvertDemandSet(demand);
	Vertex p_source = demandArray[0];
	Vertex p_dest = demandArray[1];
	visit_set = BuildVisitVertexSet(demandArray);
	/*Create all the edges*/
	vector<Edge> all_edges = BuildAllEdges(topo,edge_num);
	set<Vertex> allVertexSet = FindVertexSet(all_edges);
	int numVertex = allVertexSet.size();
	/*Build the graph*/
	LGraph gra = BuildGraph(numVertex,all_edges,visit_set);
		/* P_ is all vertex set subtrace p_source and p_dest */
	set<Vertex> P_ = BuildP_Set(allVertexSet,p_source,p_dest);
	un_visit_set = BuildUnVisitVertexSet(P_,visit_set);

	/*DFS to see if p_source and p_dest are connected or not, if not then  output no solution */
	bool connect = DFS(gra,p_source,p_dest);
	if (!connect){
		//cout<<"No solution at all!!!"<<endl;
		return;
	}
	else{//cout<<"p_source and p_dest are connected "<<endl;
		}
	Record minRecord = new RecordNode;
	minRecord->weightSum = INFINITY_DISTANCE;
	/*if the visit_set is empty,then use Dijkstra algorithm to find the shortest path*/
	if(visit_set.empty()){
		minRecord = Dijkstra(gra,p_source,p_dest);
	}
	/* Use Dynamic programming method to find all paths that visit the specified vertex*/
	else{
		PtrToAdjVNode thisNode = gra->Graph[p_source].firstEdge;
		while (thisNode!= NULL) {
			// deep copy of A and B;
			set<Vertex> A1 = A;
			set<Vertex> B1 = B;
			Record a_record = new RecordNode;
			Vertex v = thisNode->AdjV;
			if(v == p_dest){
			}
			else{
				if(visit_set.count(v)){
					A1.insert(v);
				}
				else if(un_visit_set.count(v)){
					B1.insert(v);
				}
				a_record->weightSum = thisNode->weight;
				a_record->path.push_back(thisNode->edgeID);
				DynamicRecursion(gra,v,p_source,p_dest,A1,B1,a_record,minRecord,visit_set,un_visit_set,begin_time);
			}
			thisNode = thisNode->next;
		}
	}
	// because of some character encode problems, I write this comment in english
	// firstly, you need to initialize a vector to store the result like this:
	vector<IDType> result;

	/*If all_records is not empty*/
	if (minRecord->path.size()){
		/*Check if the result is right*/
	/*	if(!IsResultCorrect(all_edges, result,p_source,p_dest)){
			cout<<"The result is wrong!"<<endl;
		}else{
			cout<<"The result is right"<<endl;
		}*/
		result = minRecord->path;
		// then print the results in the result.csv
		for(std::vector<IDType>::iterator it = result.begin(); it != result.end(); ++it){
			record_result(*it);
		}

	}else{}

	//cout<<"The total time is "<<float(clock() - begin_time)/CLOCKS_PER_SEC;
}
/*--------------------------------------------------------------------------------------------------------*/

/*Build all the edges using information stored in the topo*/
vector<Edge> BuildAllEdges(char *topo[5000], int edge_num)
{
	vector<Edge> all_edges ;
	for(int i=0;i<edge_num;i++){
		//cout<<topo[i]<<endl;
		int *array;
		array = CharToEdge(topo[i]);
		Edge a_edge = CreateEdge(array);
		all_edges.push_back(a_edge);
	}
	return all_edges;
}

/*Convert the string which contains the information of edge to integer array*/
int* CharToEdge(char *edge)
{
	int *array = new int[4];
	string strArray[4] = {"","","",""};
	unsigned short count = 0;
	for(int i =0;i <strlen(edge) ;i++){
		if(edge[i] == ',')   {// the data was splited by','
			array[count] = atoi(strArray[count].c_str());	//convert string to int
			count++;
		}else{
			strArray[count].push_back(edge[i]);
		}

	}
    array[count] = atoi(strArray[count].c_str());
    return array;
}

/*Convert the string which contains the information of demand to integer array*/
vector<Vertex> ConvertDemandSet(char *demand)
{
	vector<Vertex> array;
	string str = "";
	for(int i =0;i <strlen(demand) ;i++){
		if(demand[i] == ',' || demand[i] == '|'){   // the data was splited by','  or'|'
		    int value = atoi(str.c_str());	//convert string to int
			array.push_back(value);
			str = "";
		}else{
			str.push_back(demand[i]);
		}

	}
    array.push_back(atoi(str.c_str())) ;
    return array;
}

/*Create an Edge*/
Edge CreateEdge(int* array)
{
		Edge a_edge = new ENode;
		a_edge->edgeID = *array;
		a_edge->v1 =  *(array+1);
		a_edge->v2 =  *(array+2);
		a_edge->weight =  *(array+3);
		delete[] array;
		return a_edge;
}
/*Count on vertexes, and return the all vertexes set*/
set<Vertex> FindVertexSet(vector<Edge>all_edges)
{
	set<Vertex> vertexSet;
	for(int i=0;i<all_edges.size();i++){
		vertexSet.insert(all_edges[i]->v1);
		vertexSet.insert(all_edges[i]->v2);
	}
	return vertexSet;
}

/*Build the Graph in link list form,store the topo informaiton in this graph*/
LGraph BuildGraph(int numV, vector<Edge> all_edges,set<Vertex>& visit_set)
{
	LGraph gra;
	Edge e;
	Vertex v;
	gra = CreateGraph(numV);
	gra->numEdge = all_edges.size();
	if (gra->numEdge != 0) {
		for (int i = 0; i < gra->numEdge; i++) {
			e = all_edges[i];
			InsertEdge(gra, e,visit_set);
		}
	}
	return gra;
}
/*Initialize a graph with numV vertex but without any edge*/
/*初始化一个有numV个顶点的但是没有边的图*/
LGraph CreateGraph(int numV)
{
	Vertex v, w;
	LGraph gra;
	gra = new GNode;
	gra->numVertex = numV;
	gra->numEdge = 0;
	for (int i = 0; i < numV; i++) {
		gra->Graph[i].firstEdge = NULL;
	}
	return gra;
}
/*Insert an edge to the graph*/
void InsertEdge(LGraph gra, Edge e,set<Vertex>& visit_set)
{
	PtrToAdjVNode newNode;
	/*插入边<v1,v2>*/
	/*为v2建立邻接点*/
	newNode = new AdjVNode;
	newNode->AdjV = e->v2;
	newNode->weight = e->weight;
	newNode->edgeID = e->edgeID;
	/*将v2插入到v1的后面，并将v1后面的元素接到v2后面*/
	PtrToAdjVNode firstNode = gra->Graph[e->v1].firstEdge ;
	if(visit_set.count(e->v2) || firstNode == NULL){
		newNode->next = gra->Graph[e->v1].firstEdge;
		gra->Graph[e->v1].firstEdge = newNode;
	}
	else{
		PtrToAdjVNode nextNode;
		nextNode = firstNode->next;
		firstNode->next = newNode;
		newNode->next = nextNode;
	}
}
/*------------------------------------------------------------------------------*/
/*Build visit vertex set that demanded,return the visit vertex set*/
set<Vertex> BuildVisitVertexSet(vector<Vertex> demandArray)
{
    set<Vertex> visit_set;
	for(int j=2;j<demandArray.size();j++){
		visit_set.insert(demandArray[j]);
	}
	return visit_set;
 }

/*Build vertex set P_,P_ is all vertex set subtrace p_source and p_dest */
set<Vertex> BuildP_Set(set<Vertex> allVertexSet,Vertex p_source,Vertex p_dest)
{
	set<Vertex> P_ = allVertexSet;   // P_ is all vertex set subtrace p_source and p_dest;
	P_.erase(p_source);
	P_ .erase(p_dest);
	return P_;
}

/*Build not necessary visit vertex set*/
set<Vertex> BuildUnVisitVertexSet(set<Vertex> P_, set<Vertex> visit_set)
{
	set<Vertex> un_visit_set = P_;
	for(set<Vertex>::iterator it = visit_set.begin(); it != visit_set.end(); ++it){
		Vertex v = *it;
		un_visit_set.erase(v);
	}
	return un_visit_set;
}

/*-------------------------------------------------------------------------------------*/

/*Use DFS algorithm to check if the source vertex and destination vertex are connected*/
bool DFS(LGraph graph,Vertex p_source,Vertex p_dest)   //从顶点p_source出发深度优先	搜索图
{

	bool *check = new bool[graph->numVertex]; /*标识符，表示该点是否已经检查*/
	bool *isIn = new bool[graph->numVertex];  /*标识符，表示该顶点是否与p_source连通 */
	for (int i = 0; i < graph->numVertex; i++) {  //初始化标识符
		check[i] = false;
		isIn[i] = false;
	}

    DFSRecur(graph,p_dest,p_source,check,isIn);
    if (isIn[p_dest]){  // the source vertex and destination vertex are connected
    	return true;
	} else{
	    return false;
	}
}
/*The recursion function part of DFS algorithm*/
/*递归DFS*/
void DFSRecur(LGraph graph,Vertex p_dest,Vertex v,bool check[],bool isIn[])
{
	if (check[v]||graph->Graph[v].firstEdge == NULL) {
		return;
	}
	check[v] = true;
	PtrToAdjVNode currentNode = graph->Graph[v].firstEdge;
	while (currentNode!= NULL) {
		int i = currentNode->AdjV;
		isIn[i] = true;
		if (i == p_dest){
			return;
		}
		DFSRecur(graph, p_dest,i,check,isIn);
		currentNode = currentNode->next;
	}
}

/*-----------------------------------------------------------------------------*/

/*Use Dijkstra Algorithm to find the shortest path from source vertex to destination vertex*/
Record Dijkstra(LGraph gra, Vertex p_source,Vertex p_dest)
{
	int numV = gra->numVertex;
	set<Vertex> uncheckedSet;
	bool *checked = new bool[numV];
	WeightType *disToSource = new 	WeightType[numV];
	Vertex *prevV = new Vertex[numV];
	IDType edgePath[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
	/*Initialize the distance*/
	for(int i = 0;i < numV; i++ ){
		uncheckedSet.insert(i);
		checked[i] = false;
		disToSource[i] = INFINITY_DISTANCE;// set the distance to infinity
	}
	disToSource[p_source] = 0; //distance from source to source
	while(!uncheckedSet.empty()){
		Vertex v = FindMinDisVertex(uncheckedSet, disToSource);
		uncheckedSet.erase(uncheckedSet.find(v));
		/* check the adjacement vertexes of v*/
		PtrToAdjVNode adVertex = gra->Graph[v].firstEdge;
		while(adVertex!= NULL){
			if(checked[adVertex->AdjV]){
			}
			else{
				WeightType altDis = disToSource[v]+adVertex->weight;
				if(altDis<disToSource[adVertex->AdjV]){
					disToSource[adVertex->AdjV] = altDis;
					 prevV[adVertex->AdjV] = v;
					 edgePath[v][adVertex->AdjV] = adVertex->edgeID;
				}
			}
			adVertex = adVertex->next;
	    }
		checked[v] = true;
		if (checked[p_dest]) break;  // The destination have been checked.
	}
	Record a_record = new RecordNode;
	a_record->weightSum = disToSource[p_dest];
	/*Retrieve the edge path information*/
	Vertex v_current = p_dest;
	Vertex w;
	stack<IDType> edges;
	while(v_current != p_source){
	    w = prevV[v_current];
	    edges.push(edgePath[w][v_current]);
	   v_current = w;
	}
	while(!edges.empty()){
		a_record->path.push_back(edges.top());
		edges.pop();
	}
	delete[] checked;
	delete[] disToSource;
	delete[] prevV;
    return a_record;
}
/*Find the minum distance  vertex in the curent record in the Dijkstra function*/
Vertex FindMinDisVertex(set<Vertex>& uncheckedSet, WeightType disToSource[])
{
	Vertex index = MAX_VERTEX_NUM;
	WeightType dis = INFINITY_DISTANCE;
	set<Vertex>::iterator it = uncheckedSet.begin();
	while (it != uncheckedSet.end()) {
		if (disToSource[*it]<dis) {
			dis = disToSource[*it];
			index = *it;
		}
		it++;
	}
	return index;
}
/*Dynamic programmng recursion function*/
void DynamicRecursion(LGraph gra,Vertex v_prev,Vertex p_source,Vertex p_dest,set<Vertex> A,set<Vertex>B,Record pre_record,\
						Record  minRecord,set<Vertex> &visit_set,set<Vertex> &un_visit_set,clock_t begin_time)
{
	//base conditon ,the time is out
	if(float((clock()-begin_time))/CLOCKS_PER_SEC > 9.9){
		return;
	}
	PtrToAdjVNode thisNode = gra->Graph[v_prev].firstEdge;
	if(!thisNode){
		delete pre_record;
	}
	while (thisNode!= NULL) {
		// deep copy of A,B and pre_record
		set<Vertex> A1 = A;
		set<Vertex> B1 = B;
		Record a_record = new RecordNode;
		*a_record = *pre_record;
		Vertex v = thisNode->AdjV;
		/*Base condition, terminate the recursion*/
		/*If the Vertex is already in A1 or B1,or it is the source vertex*/
		if(A1.count(v) ||B1.count(v) || (v == p_source)){
		}
		/*If it reaches the destination vertex and visited all the demand vertexes*/
		else if(v == p_dest){
			if(A1.size() == visit_set.size()){     // reaches the destination vertex
				a_record->weightSum += thisNode->weight;
				a_record->path.push_back(thisNode->edgeID);
				if(a_record->weightSum < minRecord->weightSum){
					minRecord->path = a_record->path;
					minRecord->weightSum = a_record->weightSum;
					delete a_record;
				}
			}
		}
		else{
			if(visit_set.count(v)){
				A1.insert(v);

			}
			else if(un_visit_set.count(v)){
				B1.insert(v);
			}
			a_record->weightSum += thisNode->weight;
			a_record->path.push_back(thisNode->edgeID);
			DynamicRecursion(gra,v,p_source, p_dest,A1,B1,a_record,minRecord,visit_set,un_visit_set,begin_time);
		}
		thisNode = thisNode->next;
	}
}

/*Check if the final result is right*/
/*bool IsResultCorrect(vector<Edge> edges, vector<IDType> result,Vertex p_source,Vertex p_dest)
{
	int num = result.size();
	if(edges[result[0]]->v1 != p_source || num > edges.size() ||\
	    edges[result[num-1]]->v2 != p_dest){
	    	return false;
		}
	for(int i = 0;i<num-1;i++){
		if(edges[result[i]]->v2 != edges[result[i+1]]->v1 ){
			return false;
		}
	}
	return true;
}*/

<file_sep>future_net topo.csv demand.csv result.csv
pause<file_sep>#ifndef __ROUTE_H__
#define __ROUTE_H__

#include <vector>
#include<iostream>
#include<set>
#include<queue>
#include<string>
#include<cstring>
#include <stdlib.h>     /* atoi */
#include<stack>

using namespace std;

/*--------------------------------------------------------------*/
#define MAX_VERTEX_NUM 600
#define INFINITY_DISTANCE 9999
/*Define the data type used in this file*/
typedef unsigned short WeightType;      // Weight type  权重数据类型
typedef unsigned short DataType;       //  Data type 顶点所储存的数据
typedef unsigned short Vertex;          // Vertex type 顶点编号数据类型
typedef unsigned short IDType;          // the  data type of ID of edge 边的编号数据类型

/*Define the structure of adjacement element */
/*定义邻接元素的结构体*/
typedef struct AdjVNode *PtrToAdjVNode;
struct AdjVNode {
	Vertex AdjV;
	IDType edgeID;
	WeightType weight;
	PtrToAdjVNode next;
};

/*Define the adjacement list in the form of array*/
/*以数组形式定义了一张邻接表*/
typedef struct VNode {
	PtrToAdjVNode firstEdge;
}AdjList[MAX_VERTEX_NUM];
//含义是：定义一个类型别名adjlist，这个类型是一个结构体类型为元素类型的长度为MaxVertexNum的数组

/*Define the structure of graph in the form of link list*/
/*链表表示的图的结构体定义*/
typedef struct GNode *PtrToGNode;
struct GNode {
	int numVertex;
	int numEdge;
	AdjList Graph;
};
typedef PtrToGNode LGraph;

/*Define the structure of edge*/
/*定义边Edge*/
typedef struct ENode *ptrToENode;
struct ENode {
	IDType edgeID;
	Vertex v1, v2;
	WeightType weight ;
};
typedef ptrToENode Edge;

/*Define the structure of record that stores the weight and the path*/
typedef struct RecordNode *ptrToRecordNode;
struct RecordNode{
	WeightType weightSum;
	vector<IDType> path;
};
typedef ptrToRecordNode Record;

/*---------------------------------------------------------------------------------------------------*/

/*This function the main Entrance to find the shortest path */
void search_route(char *graph[5000], int edge_num, char *condition);

/*Build all the edges using information stored in the topo*/
vector<Edge> BuildAllEdges(char* topo[5000], int edge_num);

/*Convert the string which contains the information of edge to integer array*/
int*  CharToEdge(char *edge);

/*Create an Edge*/
Edge CreateEdge(int* array);

/*Build the Graph in link list form,store the topo informaiton in this graph*/
LGraph BuildGraph(int numVertex, vector<Edge> all_edges,set<Vertex>& visit_set);

/*Initialize a graph with numV vertex but without any edge*/
/*初始化一个有numV个顶点的但是没有边的图*/
LGraph CreateGraph(int numV);

/*Insert an edge to the graph*/
void InsertEdge(LGraph gra, Edge e,set<Vertex>& visit_set);

/*Convert the string which contains the information of demand to integer array*/
vector<Vertex> ConvertDemandSet(char *demand);

/*Count on vertexes, and return the all vertexes set*/
set<Vertex> FindVertexSet(vector<Edge>all_edges);

/*Build visit vertex set that demanded,return the visit vertex set*/
set<Vertex> BuildVisitVertexSet(vector<Vertex> demandArray);

/*Build vertex set P_,P_ is all vertex set subtrace p_source and p_dest */
set<Vertex> BuildP_Set(set<Vertex> allVertexSet,Vertex p_source,Vertex p_dest);

/*Build not necessary visit vertex set*/
set<Vertex> BuildUnVisitVertexSet(set<Vertex> P_, set<Vertex> visit_set);

/*Use DFS algorithm to check if the source vertex and destination vertex are connected*/
bool DFS(LGraph gra,Vertex p_source,Vertex p_dest);
/*The recursion function part of DFS algorithm*/
void DFSRecur(LGraph gra,Vertex p_dest,Vertex v,bool check[],bool isIn[]);

/*Use Dijkstra Algorithm to find the shortest path from source vertex to destination vertex*/
Record Dijkstra(LGraph gra, Vertex p_source,Vertex p_dest);
/*Find the minum distance  vertex in the curent record in the Dijkstra function*/
Vertex FindMinDisVertex(set<Vertex>& uncheckedSet, WeightType disToSource[]);

/*Dynamic programmng recursion function,if find a feasible solution,add it to all_records*/
void DynamicRecursion(LGraph gra,Vertex v_prev,Vertex p_source,Vertex p_dest,set<Vertex> A,set<Vertex>B,Record pre_record,\
						Record all_records,set<Vertex> &visit_set,set<Vertex> &un_visit_set,clock_t begin_time);

/*Check if the final result is right,if right,return true*/
//bool IsResultCorrect(vector<Edge> edges, vector<IDType> result,Vertex p_source,Vertex p_dest);
/*----------------------------------------------------------------------------------------------------------*/
#endif
<file_sep>//#include "munkres.h"
<file_sep>#include <vector>
#include <stdio.h>
#include <string>
#include <iostream>
#include <set>

#ifndef __ROUTE_H__
#define __ROUTE_H__

void search_route(char *graph[5000], int edge_num, char *condition);

#endif
<file_sep>#include <vector>
#include<iostream>
#include<set>
#include<queue>
#include<string>
#include<cstring>
#include <stdlib.h>     /* atoi */
#include<stack>

#include "route.h"
#include "lib_record.h"
#include <stdio.h>

/*---------------------------------------------------------------------------------------------------*/
//你要完成的功能总入口
void search_route(char *topo[5000], int edge_num, char *demand)
{
	/*Create all the edges*/
	vector<Edge> all_edges = BuildAllEdges(topo,edge_num);
	set<Vertex> allVertexSet = FindVertexSet(all_edges);
	int numVertex = allVertexSet.size();
	/*Build the graph*/
	LGraph gra = BuildGraph(numVertex,all_edges);
	/*Assign Id to the source vertex and destination vertex, and build the must visited vertex set S
	and not necessary vistied vertex set  S_*/
	vector<Vertex> demandArray = ConvertDemandSet(demand);
	Vertex p_source = demandArray[0];
	Vertex p_dest = demandArray[1];
	/* P_ is all vertex set subtrace p_source and p_dest */
	set<Vertex> P_ = BuildP_Set(allVertexSet,p_source,p_dest);
	/* A is to record already visited vertex in visit_set
	   B is to record already visited vertex in un_visit_set  */
	set<Vertex> visit_set,un_visit_set,A,B;
	set<Vertex> vertexToCut;
	visit_set = BuildVisitVertexSet(demandArray);
	un_visit_set = BuildUnVisitVertexSet(P_,visit_set);

	/*DFS to see if p_source and p_dest are connected or not, if not then  output no solution,
	  and record vertex to cut*/
	bool connect = DFS(gra,p_source,p_dest,vertexToCut);
	if (!connect){
		cout<<"No solution at all!!!"<<endl;
		return;
	}
	else
	    cout<<"p_source and p_dest are connected "<<endl;

	/*Build the cost matrix and ID matrix*/
	WeightType ** costs = BuildWeightMatrix(all_edges,numVertex);
	IDType ** IDs = BuildIDMatrix(all_edges,numVertex);
	matrix matrix_cost = matrix(costs,numVertex,numVertex);
	matrix matrix_ID = matrix(IDs,numVertex,numVertex);
	/* Put the source vertex in 0,and put the destination at last in matrix*/
	/*Cut the vertex not connected*/
	FitMatrix(matrix_cost,matrix_ID,p_source,p_dest,vertexToCut);

	/*if the visit_set is empty,then use Dijkstra algorithm to find the shortest path*/
	if(visit_set.empty()){
		Record a_record = Dijkstra(gra,p_source,p_dest);
	}

	//Test for class matrix

	// because of some character encode problems, I write this comment in english
	// firstly, you need to initialize a vector to store the result like this:
	vector<IDType> result;
	// then print the results in the result.csv
 	for(std::vector<IDType>::iterator it = result.begin(); it != result.end(); ++it){
	  record_result(*it);
	  cout<<*it<<"|";
	}
}
/*--------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------*/

/*Use DFS algorithm to check if the source vertex and destination vertex are connected*/
bool DFS(LGraph graph,Vertex p_source,Vertex p_dest,set<Vertex>& cut)   //从顶点p_source出发深度优先	搜索图
{

	bool *check = new bool[graph->numVertex]; /*标识符，表示该点是否已经检查*/
	bool *isIn = new bool[graph->numVertex];  /*标识符，表示该顶点是否与p_source连通 */
	for (int i = 0; i < graph->numVertex; i++) {  //初始化标识符
		check[i] = false;
		isIn[i] = false;
	}

    DFSRecur(graph,p_dest,p_source,check,isIn);
    for (int i = 0; i < graph->numVertex; i++){ // To record the vertex can't reach from souce vertex
		if(!isIn[i] && i!=p_source)
			cut.insert(i);
	}
    if (isIn[p_dest]){  // the source vertex and destination vertex are connected
    	return true;
	} else{
	    return false;
	}
}
/*The recursion function part of DFS algorithm*/
/*递归DFS*/
void DFSRecur(LGraph graph,Vertex p_dest,Vertex v,bool check[],bool isIn[])
{
	if (check[v]||graph->Graph[v].firstEdge == NULL) {
		return;
	}
	check[v] = true;
	PtrToAdjVNode currentNode = graph->Graph[v].firstEdge;
	while (currentNode!= NULL) {
		int i = currentNode->AdjV;
		isIn[i] = true;
		/*if (i == p_dest){
			return;
		}*/
		DFSRecur(graph, p_dest,i,check,isIn);
		currentNode = currentNode->next;
	}
}

/*-----------------------------------------------------------------------------*/

/*Use Dijkstra Algorithm to find the shortest path from source vertex to destination vertex*/
Record Dijkstra(LGraph gra, Vertex p_source,Vertex p_dest)
{
	int numV = gra->numVertex;
	set<Vertex> uncheckedSet;
	bool *checked = new bool[numV];
	WeightType *disToSource = new 	WeightType[numV];
	Vertex *prevV = new Vertex[numV];
	IDType edgePath[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
	/*Initialize the distance*/
	for(int i = 0;i < numV; i++ ){
		uncheckedSet.insert(i);
		checked[i] = false;
		disToSource[i] = INFINITY_DISTANCE;// set the distance to infinity
	}
	disToSource[p_source] = 0; //distance from source to source
	while(!uncheckedSet.empty()){
		Vertex v = FindMinDisVertex(uncheckedSet, disToSource);
		uncheckedSet.erase(uncheckedSet.find(v));
		/* check the adjacement vertexes of v*/
		PtrToAdjVNode adVertex = gra->Graph[v].firstEdge;
		while(adVertex!= NULL){
			if(checked[adVertex->AdjV]){
			}
			else{
				WeightType altDis = disToSource[v]+adVertex->weight;
				if(altDis<disToSource[adVertex->AdjV]){
					disToSource[adVertex->AdjV] = altDis;
					 prevV[adVertex->AdjV] = v;
					 edgePath[v][adVertex->AdjV] = adVertex->edgeID;
				}
			}
			adVertex = adVertex->next;
	    }
		checked[v] = true;
		if (checked[p_dest]) break;  // The destination have been checked.
	}
	Record a_record = new RecordNode;
	a_record->weightSum = disToSource[p_dest];
	/*Retrieve the edge path information*/
	Vertex v_current = p_dest;
	Vertex w;
	stack<IDType> edges;
	while(v_current != p_source){
	    w = prevV[v_current];
	    edges.push(edgePath[w][v_current]);
	   v_current = w;
	}
	while(!edges.empty()){
		a_record->path.push_back(edges.top());
		edges.pop();
	}
	delete[] checked;
	delete[] disToSource;
	delete[] prevV;
    return a_record;
}
/*Find the minum distance  vertex in the curent record in the Dijkstra function*/
Vertex FindMinDisVertex(set<Vertex>& uncheckedSet, WeightType disToSource[])
{
	Vertex index = MAX_VERTEX_NUM;
	WeightType dis = INFINITY_DISTANCE;
	set<Vertex>::iterator it = uncheckedSet.begin();
	while (it != uncheckedSet.end()) {
		if (disToSource[*it]<dis) {
			dis = disToSource[*it];
			index = *it;
		}
		it++;
	}
	return index;
}

/*Check if the final result is right*/
bool IsResultCorrect(vector<Edge> edges, vector<IDType> result,Vertex p_source,Vertex p_dest)
{
	int num = result.size();
	if(edges[result[0]]->v1 != p_source || num > edges.size() ||\
	    edges[result[num-1]]->v2 != p_dest){
	    	return false;
		}
	for(int i = 0;i<num-1;i++){
		if(edges[result[i]]->v2 != edges[result[i+1]]->v1 ){
			return false;
		}
	}
	return true;
}

/* Put the source vertex in 0,and put the destination at last in matrix*/
void FitMatrix(matrix &matrix_cost, matrix &matrix_ID,Vertex p_source,Vertex p_dest,set<Vertex> & vertexToCut)
{
	/* Put the source vertex in 0,and put the destination at last in matrix*/
	matrix_cost.exchangeColumns(0,p_source);
	matrix_cost.exchangeRows(0,p_source);
	matrix_cost.exchangeColumns(p_dest,matrix_cost.columns()-1);
	matrix_cost.exchangeRows(p_dest,matrix_cost.rows()-1);
	matrix_ID.exchangeColumns(0,p_source);
	matrix_ID.exchangeRows(0,p_source);
	matrix_ID.exchangeColumns(p_dest,matrix_cost.columns()-1);
	matrix_ID.exchangeRows(p_dest,matrix_cost.rows()-1);
	/*Prunning: cut the verteces not connected*/
	if(!vertexToCut.empty())
			for(std::set<Vertex>::iterator it = vertexToCut.begin();it!=vertexToCut.end();it++){
				cout<<" cut is"<< *it<<endl;
				matrix_cost.deleteRowAndColumn(*it);
				matrix_ID.deleteRowAndColumn(*it);
			}
}

<file_sep>#include <string>
#include <vector>
#include <stack>
#include <set>
#include <cstdlib>     /* atoi */
#include <string.h>
#include <iostream>
#include <list> /* insert from front and end, for update_conects function*/
using std::string;
class Route{
	public:
		int id,
			sour,
			dest,
			cost;
        std::vector<int> conects;//按经过点排序

        int load_value(string id,string sour,string dest,string cost);
};

int Route::load_value(string id,string sour,string dest,string cost){
        this->id=std::atoi(id.c_str());
        this->sour=std::atoi(sour.c_str());
        this->dest=std::atoi(dest.c_str());
        this->cost=std::atoi(cost.c_str());
        return 0;
}

std::vector<std::string> str_split(char*str,  const char*d);
std::vector<Route> rawTopo_to_routes(char *topo[5000], int edge_num);
std::set<int> get_vertices(char*rawVertices);
int update_conects(std::vector<Route>&,std::vector<int>);
void printStack(std::stack<Route>);
std::vector<int> stackToResult(std::stack<Route> );
int getCost(std::stack<Route> mystack);
void outPutResult(std::stack<Route> pastStack);

//implement
std::vector<std::string> str_split(char*str,  const char d){
    std::vector<std::string> strArray;
    std::string tempStr;
    while(*str!=NULL){
        tempStr.clear();
        while(*str!=d){
            tempStr+=str[0];
            str++;
            if(*str==NULL){
                break;
            }
        }
        if(!tempStr.empty()){
            strArray.push_back(tempStr);
            str++;
        }
    }
    return strArray;
}

std::vector<Route> rawTopo_to_routes(char *topo[5000], int edge_num){
		std::vector<Route> routes;
		Route tempRoute;
		std::vector<string> strArray;
		char*p;
		for(int i=0; i<edge_num; ++i){
            p=topo[i];
            strArray=str_split(p,',');
            tempRoute.load_value(strArray[0],strArray[1],strArray[2],strArray[3]);

			routes.push_back(tempRoute);
		}
		return routes;
}

std::set<int> get_vertices(const char* rawVertices){
    std::set<int> vertices;
    char tChar[200]={0};
    strcpy(tChar,rawVertices);
    std::vector<string> verticesArray=str_split(tChar,'|');

    for(std::vector<string>::iterator it=verticesArray.begin();it!=verticesArray.end();it++){

        vertices.insert(std::atoi(it->c_str()));
    }
    return vertices;
}

int update_conects(std::vector<Route>& routes,std::set<int> vertices){

    std::vector<int> nodeArray[1000];
    std::vector<int> tConnects;
    std::list<int> forSort;

    //遍历route列表，记录每一个节点的全部下级路径id到结点列表
    for(std::vector<Route>::iterator it=routes.begin();it!=routes.end();it++){
        nodeArray[it->sour].push_back(it->id);
    }
    //遍历route列表，将每一个路径的下级路径id全部记录起来，
    for(std::vector<Route>::iterator it=routes.begin();it!=routes.end();it++){
        forSort.clear();
        it->conects=nodeArray[it->dest];
    }

    return 0;
}

void printStack(std::stack<Route> mystack){
    Route currRoute;
    while(!mystack.empty()){
        currRoute=mystack.top();
        mystack.pop();
        std::cout<<currRoute.id<<'|'<<currRoute.sour<<'|'<<currRoute.dest<<'|'<<currRoute.cost<<std::endl;
    }
    std::cout<<"----------"<<std::endl;
}

std::vector<int> stackToResult(std::stack<Route> mystack){
    std::vector<int> result;
    while(!mystack.empty()){
        result.push_back(mystack.top().id);
        mystack.pop();
    }
    return result;
}

int getCost(std::stack<Route> mystack){
    int cost=0;
    while(!mystack.empty()){
        cost+=mystack.top().cost;
        mystack.pop();
    }
    return cost;
}

void outPutResult(std::stack<Route> pastStack){
	std::vector<int> result;
    result=stackToResult(pastStack);
	for(std::vector<int>::reverse_iterator it = result.rbegin(); it != result.rend(); ++it){
		record_result(*it);
		std::cout<<*it<<'|';
	}
    std::cout<<std::endl<<"cost:"<<getCost(pastStack)<<std::endl;
}

<file_sep>#include "matrix.h"

using namespace std;
/*Constructors, to initialize the matrix*/
matrix::matrix()
{
	m_rows = 0;
  m_columns = 0;
  m_matrix = NULL;
}
matrix::matrix(const int rows,const int columns){
	m_matrix = NULL;
  resize(rows, columns);
}
matrix::matrix(int **data,const int rows,const int columns){
	m_rows = rows;
	m_columns = columns;
	m_matrix = data;
}
matrix::matrix(const matrix &other){
	if ( other.m_matrix != NULL ) {
    // copy arrays
    m_matrix = NULL;
    resize(other.m_rows, other.m_columns);
    for ( int i = 0 ; i < m_rows ; i++ ) {
      for ( int j = 0 ; j < m_columns ; j++ ) {
        m_matrix[i][j] = other.m_matrix[i][j];
      }
    }
  } else {
    m_matrix = NULL;
    m_rows = 0;
    m_columns = 0;
  }
}
/*Change the size of the matrix*/
void matrix::resize(const int rows,const int columns, const int default_value){
  if ( m_matrix == NULL ) {
    // alloc arrays
    m_matrix = new int*[rows]; // rows
    for ( int i = 0 ; i < rows ; i++ ) {
      m_matrix[i] = new int[columns]; // columns
    }
    m_rows = rows;
    m_columns = columns;
    clear();
  } else {
    // save array pointer
    int **new_matrix;
    // alloc new arrays
    new_matrix = new int*[rows]; // rows
    for ( int i = 0 ; i < rows ; i++ ) {
      new_matrix[i] = new int[columns]; // columns
      for ( int j = 0 ; j < columns ; j++ ) {
        new_matrix[i][j] = default_value;
      }
    }

    // copy data from saved pointer to new arrays
    int minrows = std::min(rows, m_rows);
    int mincols = std::min(columns, m_columns);
    for ( int x = 0 ; x < minrows ; x++ ) {
      for ( int y = 0 ; y < mincols ; y++ ) {
        new_matrix[x][y] = m_matrix[x][y];
      }
    }

    // delete old arrays
    if ( m_matrix != NULL ) {
      for ( int i = 0 ; i < m_rows ; i++ ) {
        delete [] m_matrix[i];
      }

      delete [] m_matrix;
    }

    m_matrix = new_matrix;
  }

  m_rows = rows;
  m_columns = columns;
}

/*Destructor*/
matrix::~matrix()
{
	if ( m_matrix != NULL ) {
    // free arrays
    for ( size_t i = 0 ; i < m_rows ; i++ ) {
      delete [] m_matrix[i];
    }

    delete [] m_matrix;
  }
  m_matrix = NULL;
}

void
matrix::clear(){
	for ( int i = 0 ; i < m_rows ; i++ ) {
    for ( int j = 0 ; j < m_columns ; j++ ) {
      m_matrix[i][j] = 0;
    }
  }
}

int &
matrix::operator () (const int x,const int y){
	assert ( x < m_rows );
  	assert ( y < m_columns );
  	assert ( m_matrix != NULL );
  	return m_matrix[x][y];
}
const int&
matrix::operator ()(const size_t x, const size_t y) const {
  assert ( x < m_rows );
  assert ( y < m_columns );
  assert ( m_matrix != NULL );
  return m_matrix[x][y];
}

/*Assign a matrix to another*/
matrix &
matrix::operator = (const matrix &other){
	if ( other.m_matrix != NULL ) {
    // copy arrays
    resize(other.m_rows, other.m_columns);
    for ( size_t i = 0 ; i < m_rows ; i++ ) {
      for ( size_t j = 0 ; j < m_columns ; j++ ) {
          m_matrix[i][j] = other.m_matrix[i][j];
      }
    }
  } else {
    // free arrays
    for ( size_t i = 0 ; i < m_columns ; i++ ) {
      delete [] m_matrix[i];
    }
    delete [] m_matrix;
    m_matrix = NULL;
    m_rows = 0;
    m_columns = 0;
  }
  return *this;
}
/*Find the min value in the specified row*/
int
matrix::findMinRow(int rowIndex){
	assert ( rowIndex < m_rows );
	assert ( m_matrix != NULL );
	int min = m_matrix[rowIndex][0];
	for(int i=0;i<m_columns;i++){
		if(m_matrix[rowIndex][i]<min){
			min = m_matrix[rowIndex][i];
		}
	}
	return min;
}
/*Find the min value in the specified row*/
int
matrix::findMinCol(int colIndex){
	assert ( colIndex < m_columns );
	assert ( m_matrix != NULL );
	int min = m_matrix[0][colIndex];
	for(int i=0;i<m_rows;i++){
		if(m_matrix[i][colIndex]<min){
			min = m_matrix[i][colIndex];
		}
	}
	return min;
}
/* Exchange two rows */
void
matrix::exchangeRows(const int r1,const int r2){
	if(r1 == r2) return;
	int* temp = new int[m_columns];
	for(int i = 0;i<m_columns;i++){
		temp[i] = m_matrix[r1][i];
		m_matrix[r1][i] = m_matrix[r2][i];
		m_matrix[r2][i] = temp[i];
	}
}
/* Exchange two columns */
void
matrix::exchangeColumns(const int c1,const int c2){
	if(c1 == c2) return;
	int* temp = new int[m_rows];
	for(int i = 0;i<m_rows;i++){
		temp[i] = m_matrix[i][c1];
		m_matrix[i][c1] = m_matrix[i][c2];
		m_matrix[i][c2] = temp[i];
	}
}
/* Delete a pair of specified row and  column*/
void
matrix::deleteRowAndColumn(int index){
	assert( index < m_rows );
	for(int j = index;j<m_columns-1;j++)
		for(int i = 0;i<m_rows;i++){
			m_matrix[i][j] = m_matrix[i][j+1];
		}
	for(int m = 0;m<m_columns;m++)
		for(int n = index;n<m_rows-1;n++){
			m_matrix[n][m] = m_matrix[n+1][m];
		}
	m_rows -= 1;
	m_columns -= 1;
	resize(m_rows,m_columns);
}
void
matrix::print_debugInformation(){
	if (m_matrix ==NULL){
		cout<<"No element here"<<endl;
		return;
	}
	cout<<"-----------------------"<<endl;
	for(int i=0;i<m_rows;i++){
		for(int j=0;j<m_columns;j++){
			cout<<m_matrix[i][j]<<" ";
		}
		cout<<endl;
	}
}

<file_sep># codeCraft2016
empty
jijjii<file_sep>/*This file is the content of munkre's algorithm to solve assignment problem*/

#ifndef MUNKRES_H_
#define MUNKRES_H_
#include<string>
#include<iostream>
#include<cmath>
#include<utility>
#include<limits>

#include "dataStructure.h"

class Munkres
{
	static const int NORMAL = 0;
    static const int STAR   = 1;
    static const int PRIME  = 2;
public:
	void solve(WeightType ** matrix_cost,int numV,set<Vertex>& visit_set,\
	            WeightType ** x_star, WeightType & z_star )
	{
		WeightType ** matrix_musk = CreateMatrix(numV,NORMAL);
		set<int> rows_cover;
		set<int> cols_cover;

	}

};

#endif
<file_sep>#ifndef __ROUTE_H__
#define __ROUTE_H__

#include <vector>
#include<iostream>
#include<set>
#include<queue>
#include<string>
#include<cstring>
#include <stdlib.h>     /* atoi */
#include<stack>

#include "dataStructure.h"
#include "matrix.h"
#include "munkres.h"
using namespace std;

/*--------------------------------------------------------------*/

/*Define the structure of record that stores the weight and the path*/
typedef struct RecordNode *ptrToRecordNode;
struct RecordNode{
	WeightType weightSum;
	vector<IDType> path;
};
typedef ptrToRecordNode Record;

/*Use DFS algorithm to check if the source vertex and destination vertex are connected*/
bool DFS(LGraph gra,Vertex p_source,Vertex p_dest,set<Vertex>& cut);
/*The recursion function part of DFS algorithm*/
void DFSRecur(LGraph gra,Vertex p_dest,Vertex v,bool check[],bool isIn[]);

/*Use Dijkstra Algorithm to find the shortest path from source vertex to destination vertex*/
Record Dijkstra(LGraph gra, Vertex p_source,Vertex p_dest);
/*Find the minum distance  vertex in the curent record in the Dijkstra function*/
Vertex FindMinDisVertex(set<Vertex>& uncheckedSet, WeightType disToSource[]);

/*Dynamic programmng recursion function,if find a feasible solution,add it to all_records*/
void DynamicRecursion(LGraph gra,Vertex v_prev,Vertex p_source,Vertex p_dest,set<Vertex> A,set<Vertex>B,Record pre_record,\
						vector<Record> & all_records,set<Vertex> &visit_set,set<Vertex> &un_visit_set);

/*Compare and find the shortes path in the records*/
vector<IDType> GetShortestPath(vector<Record> &records);

/*Check if the final result is right,if right,return true*/
bool IsResultCorrect(vector<Edge> edges, vector<IDType> result,Vertex p_source,Vertex p_dest);
/*Fit the matrix,adapt the positon of source vertex and destination vertex,and cut the verteces notconnected*/
void FitMatrix(matrix &matrix_cost, matrix &matrix_ID,Vertex p_source,Vertex p_dest,set<Vertex> & vertexToCut);
/*----------------------------------------------------------------------------------------------------------*/
#endif
<file_sep>#ifndef DATASTRUCTURE_H_
#define DATASTRUCTURE_H_
#include<set>
#include<vector>
#include<iostream>
#include<cstdlib>
#include<string>
#include<string.h>  /*for strlen()*/
using namespace std;
#define MAX_VERTEX_NUM 600
#define INFINITY_DISTANCE 9999
#define NONE_EDGE -1
/*Define the data type used in this file*/
typedef int WeightType;      // Weight type  权重数据类型
typedef int DataType;       //  Data type 顶点所储存的数据
typedef int Vertex;          // Vertex type 顶点编号数据类型
typedef int IDType;          // the  data type of ID of edge 边的编号数据类型

/*Define the structure of adjacement element */
/*定义邻接元素的结构体*/
typedef struct AdjVNode *PtrToAdjVNode;
struct AdjVNode {
	Vertex AdjV;
	IDType edgeID;
	WeightType weight;
	PtrToAdjVNode next;
};

/*Define the adjacement list in the form of array*/
/*以数组形式定义了一张邻接表*/
typedef struct VNode {
	PtrToAdjVNode firstEdge;
}AdjList[MAX_VERTEX_NUM];
//含义是：定义一个类型别名adjlist，这个类型是一个结构体类型为元素类型的长度为MaxVertexNum的数组

/*Define the structure of graph in the form of link list*/
/*链表表示的图的结构体定义*/
typedef struct GNode *PtrToGNode;
struct GNode {
	int numVertex;
	int numEdge;
	AdjList Graph;
};
typedef PtrToGNode LGraph;

/*Define the structure of edge*/
/*定义边Edge*/
typedef struct ENode *ptrToENode;
struct ENode {
	IDType edgeID;
	Vertex v1, v2;
	WeightType weight ;
};
typedef ptrToENode Edge;

/*---------------------------------------------------------------------------------------------------*/

/*This function the main Entrance to find the shortest path */
void search_route(char *graph[5000], int edge_num, char *condition);

/*Build all the edges using information stored in the topo*/
vector<Edge> BuildAllEdges(char* topo[5000], int edge_num);

/*Convert the string which contains the information of edge to integer array*/
int* CharToEdge(char *edge);

/*Create an Edge*/
Edge CreateEdge(int* array);

/*Build the Graph in link list form,store the topo informaiton in this graph*/
LGraph BuildGraph(int numVertex, vector<Edge> all_edges);

/*Initialize a graph with numV vertex but without any edge*/
/*初始化一个有numV个顶点的但是没有边的图*/
LGraph CreateGraph(int numV);

/*Insert an edge to the graph*/
void InsertEdge(LGraph gra, Edge e);

/*Convert the string which contains the information of demand to integer array*/
vector<Vertex> ConvertDemandSet(char *demand);

/*Count on vertexes, and return the all vertexes set*/
set<Vertex> FindVertexSet(vector<Edge>all_edges);

/*Build visit vertex set that demanded,return the visit vertex set*/
set<Vertex> BuildVisitVertexSet(vector<Vertex> demandArray);

/*Build vertex set P_,P_ is all vertex set subtrace p_source and p_dest */
set<Vertex> BuildP_Set(set<Vertex> allVertexSet,Vertex p_source,Vertex p_dest);

/*Build not necessary visit vertex set*/
set<Vertex> BuildUnVisitVertexSet(set<Vertex> P_, set<Vertex> visit_set);

/*Build weight matrix*/
WeightType ** BuildWeightMatrix(vector<Edge> edges,int numV);
/*Build the edge ID matrix*/
IDType ** BuildIDMatrix(vector<Edge> edges,int numV);

/*Create a 2d dynamic matrix*/
WeightType **CreateMatrix(int numV,int value);

/*Free the memory of the matrix*/
void DeleteMatrix(WeightType **ma,int num);

#endif
<file_sep>#ifndef MATRIX_H
#define MATRIX_H

#include<cstdlib>
#include<iostream>
#include<string>
#include <cassert>
#include <algorithm>    // std::min
#include<set>
#include<vector>

#include "dataStructure.h"
using namespace std;

class matrix
{
public:
	// constructor
	matrix();
	matrix(const int rows,const int columns);
	matrix(int **data,const int rows,const int columns);
	matrix(const matrix &other);
	// destructor
	~matrix();

	/* Operation below modify the matrix in place*/
	/* Change the size of matrix*/
	void resize(const int rows,const int columns, const int default_value = 0);
	/* Clear the matrix, make all the elements be zeros */
	void clear();
	/* Assign one matrix to another*/
	matrix & operator = (const matrix &other);
	/* Get access to the element in the position (x,y)*/
	int & operator()(const int x,const int y);
	const int & operator ()(const size_t x, const size_t y) const;
	/*Return the number of rows*/
	inline int columns() const { return m_columns;}
	/*Return the number of columns*/
    inline int rows() const { return m_rows;}
	void print_debugInformation();
	/*Find the min value in the specified row*/
	int findMinRow(int rowIndex);
	/*Find the min value in the specified row*/
	int findMinCol(int colIndex);
	/* Exchange two rows */
	void exchangeRows(const int r1,const int r2);
	/* Exchange two columns */
	void exchangeColumns(const int c1,const int c2);
	/* Delete a  pair of specified row and  column*/
	void deleteRowAndColumn( int index);
protected:

private:
	int ** m_matrix; // 2 dimensional dynamic array
	int m_rows;
	int m_columns;
};

#endif
<file_sep>#include <vector>
#include <set>
#include "route.h"
#include "lib_record.h"
//#include <stdio.h>
#include <string>
#include <iostream>
//#include <cstdlib>     /* atoi */
#include "preprocess.h"
#include <stack>
#include <bitset>         // std::bitset
#include <ctime> //clock
using std::vector;
using std::string;
using std::set;
using std::stack;
using std::bitset;

void search_route(char *topo[5000], int edge_num, char *demand)
{
    //时间启动
    int start_s,stop_s;
    start_s=clock();

	vector<Route> routes=rawTopo_to_routes(topo, edge_num);
	vector<string> tDemand=str_split(demand,',');
	std::vector<int> result;
    int pstart=std::atoi(tDemand[0].c_str());
    int pend=std::atoi(tDemand[1].c_str());
    stack<Route> mainStack, pastStack, finalPath;
    int cost=100000;
    Route currRoute;
    set<int> vertices=get_vertices(tDemand[2].c_str());
    bitset<600> pastNode;
    update_conects(routes,vertices);
    bool successed;

    //主栈初始化，将起点为pstart的点压入
    for(vector<Route>::iterator it=routes.begin();it!=routes.end();it++){
        if(it->sour==pstart){
            mainStack.push(*it);
        }
    }
    pastNode.reset();
    //深度遍历，循环开始
    while(!mainStack.empty()){
//        std::cout<<"mastack:"<<std::endl;
//        printStack(mainStack);
//        std::cout<<"pastack:"<<std::endl;
//        printStack(pastStack);
        currRoute=mainStack.top();
        mainStack.pop();
        if(pastNode.test(currRoute.dest)){
            //当前点已经经过，舍弃
            //失败路径,弹回起始点
            while(!pastStack.empty()&&!mainStack.empty()&&pastStack.top().dest!=mainStack.top().sour){
                pastNode.set(pastStack.top().dest,false);
                pastStack.pop();
            }
        }
        else{
            //当前点未经过
            pastStack.push(currRoute);//路径储存
            pastNode.set(currRoute.dest,true);//结点储存
            if(currRoute.dest!=pend){
                //非终点,将子路径全部压入
                //不在必须点中先入
                for(vector<int>::iterator it=currRoute.conects.begin();it!=currRoute.conects.end();it++){
                    if(vertices.find(routes[*it].dest)==vertices.end()){
                        mainStack.push(routes[*it]);
                    }
                }
                //重新遍历一遍，在必须点中入栈
                for(vector<int>::iterator it=currRoute.conects.begin();it!=currRoute.conects.end();it++){
                    if(vertices.find(routes[*it].dest)!=vertices.end()){
                        mainStack.push(routes[*it]);
                    }
                }
            }
            else{
                //终点
                //大于9000ms退出
                stop_s=clock();
                if((stop_s-start_s)/double(CLOCKS_PER_SEC)*1000>9000){
                    break;
                }
                //检查路径是否通过所有必须点
                successed=false;
                for(set<int>::iterator it=vertices.begin();it!=vertices.end();it++){
                    if(pastNode.test(*it)){
                        //必须点在经过点中
                        successed=true;
                    }
                    else{
                        //否则置否，跳出
                        successed=false;
                        break;
                    }
                }
                if(successed){
                    //成功路径
                    if(getCost(pastStack)<cost){
                        cost=getCost(pastStack);
                        finalPath=pastStack;
                    }
                }
                else{
                    //失败路径,弹回起始点
                    while(!pastStack.empty()&&!mainStack.empty()&&pastStack.top().dest!=mainStack.top().sour){
                        pastNode.set(pastStack.top().dest,false);
                        pastStack.pop();
                    }
                }
            }
        }
    }
    outPutResult(finalPath);
}

<file_sep>#ifndef __LIB_RECORD_H__
#define __LIB_RECORD_H__

//将结果记录到result缓冲区
extern void record_result(const int edge);

#endif
<file_sep>/*This file contains the data structure here*/

#include"dataStructure.h"

using namespace std;

/*Build all the edges using information stored in the topo*/
vector<Edge> BuildAllEdges(char *topo[5000], int edge_num)
{
	vector<Edge> all_edges ;
	for(int i=0;i<edge_num;i++){
		//cout<<topo[i]<<endl;
		int *array;
		array = CharToEdge(topo[i]);
		Edge a_edge = CreateEdge(array);
		all_edges.push_back(a_edge);
	}
	return all_edges;
}

/*Convert the string which contains the information of edge to integer array*/
int* CharToEdge(char *edge)
{
	int*array = new int[4];
	string strArray[4] = {"","","",""};
	int count = 0;
	for(int i =0;i <strlen(edge) ;i++){
		if(edge[i] == ',')   {// the data was splited by','
			array[count] = atoi(strArray[count].c_str());	//convert string to int
			count++;
		}else{
			strArray[count].push_back(edge[i]);
		}

	}
    array[count] = atoi(strArray[count].c_str());
    return array;
}

/*Convert the string which contains the information of demand to integer array*/
vector<Vertex> ConvertDemandSet(char *demand)
{
	vector<Vertex> array;
	string str = "";
	for(int i =0;i <strlen(demand) ;i++){
		if(demand[i] == ',' || demand[i] == '|'){   // the data was splited by','  or'|'
		    int value = atoi(str.c_str());	//convert string to int
			array.push_back(value);
			str = "";
		}else{
			str.push_back(demand[i]);
		}

	}
    array.push_back(atoi(str.c_str())) ;
    return array;
}

/*Create an Edge*/
Edge CreateEdge(int* array)
{
		Edge a_edge = new ENode;
		a_edge->edgeID = *array;
		a_edge->v1 =  *(array+1);
		a_edge->v2 =  *(array+2);
		a_edge->weight =  *(array+3);
		delete[] array;
		return a_edge;
}
/*Count on vertexes, and return the all vertexes set*/
set<Vertex> FindVertexSet(vector<Edge>all_edges)
{
	set<Vertex> vertexSet;
	for(int i=0;i<all_edges.size();i++){
		vertexSet.insert(all_edges[i]->v1);
		vertexSet.insert(all_edges[i]->v2);
	}
	return vertexSet;
}

/*Build the Graph in link list form,store the topo informaiton in this graph*/
LGraph BuildGraph(int numV, vector<Edge> all_edges)
{
	LGraph gra;
	Edge e;
	Vertex v;
	gra = CreateGraph(numV);
	gra->numEdge = all_edges.size();
	if (gra->numEdge != 0) {
		for (int i = 0; i < gra->numEdge; i++) {
			e = all_edges[i];
			InsertEdge(gra, e);
		}
	}
	return gra;
}
/*Initialize a graph with numV vertex but without any edge*/
/*初始化一个有numV个顶点的但是没有边的图*/
LGraph CreateGraph(int numV)
{
	Vertex v, w;
	LGraph gra;
	gra = new GNode;
	gra->numVertex = numV;
	gra->numEdge = 0;
	for (int i = 0; i < numV; i++) {
		gra->Graph[i].firstEdge = NULL;
	}
	return gra;
}
/*Insert an edge to the graph*/
void InsertEdge(LGraph gra, Edge e)
{
	PtrToAdjVNode newNode;
	/*插入边<v1,v2>*/
	/*为v2建立邻接点*/
	newNode = new AdjVNode;
	newNode->AdjV = e->v2;
	newNode->weight = e->weight;
	newNode->edgeID = e->edgeID;
	/*将v2插入到v1的后面，并将v1后面的元素接到v2后面*/
	newNode->next = gra->Graph[e->v1].firstEdge;
	gra->Graph[e->v1].firstEdge = newNode;
}
/*------------------------------------------------------------------------------*/
/*Build visit vertex set that demanded,return the visit vertex set*/
set<Vertex> BuildVisitVertexSet(vector<Vertex> demandArray)
{
    set<Vertex> visit_set;
	for(int j=2;j<demandArray.size();j++){
		visit_set.insert(demandArray[j]);
	}
	return visit_set;
 }

/*Build vertex set P_,P_ is all vertex set subtrace p_source and p_dest */
set<Vertex> BuildP_Set(set<Vertex> allVertexSet,Vertex p_source,Vertex p_dest)
{
	set<Vertex> P_ = allVertexSet;   // P_ is all vertex set subtrace p_source and p_dest;
	P_.erase(p_source);
	P_ .erase(p_dest);
	return P_;
}

/*Build not necessary visit vertex set*/
set<Vertex> BuildUnVisitVertexSet(set<Vertex> P_, set<Vertex> visit_set)
{
	set<Vertex> un_visit_set = P_;
	for(set<Vertex>::iterator it = visit_set.begin(); it != visit_set.end(); ++it){
		Vertex v = *it;
		un_visit_set.erase(v);
	}
	return un_visit_set;
}
/*Build weight matrix*/
WeightType ** BuildWeightMatrix(vector<Edge> edges,int numV)
{
	/*apply a dunamic 2d array*/
	WeightType **matrix;
	matrix = new WeightType*[numV];
	for(int i=0;i<numV;i++){
		matrix[i] = new WeightType[numV];
	}
	for(int j =0;j<numV;j++)
		for(int k =0;k<numV;k++){
				matrix[j][k] = INFINITY_DISTANCE;
		}
	for (int j = 0; j < edges.size(); j++) {
			Edge e = edges[j];
			matrix[e->v1][e->v2] = e->weight;
	}
		return matrix;
}
/*Build the edge ID matrix*/
IDType ** BuildIDMatrix(vector<Edge> edges,int numV)
{
	IDType **matrix;
	matrix = new IDType*[numV];
	for(int i=0;i<numV;i++){
		matrix[i] = new IDType[numV];
	}
	for(int j =0;j<numV;j++)
		for(int k =0;k<numV;k++){
				matrix[j][k] = NONE_EDGE;
		}
	for (int m = 0; m < edges.size(); m++) {
			Edge e = edges[m];
			matrix[e->v1][e->v2] = e->edgeID;
		}
		return matrix;
}

/*Create a 2d dynamic matrix*/
WeightType **CreateMatrix(int numV,int value)
{
		WeightType **matrix;
	matrix = new WeightType*[numV];
	for(int i=0;i<numV;i++){
		matrix[i] = new WeightType[numV];
	}
	for(int j =0;j<numV;j++)
		for(int k =0;k<numV;k++){
				matrix[j][k] = value;
		}
		return matrix;
}
/*Free the memory of the matrix*/
void DeleteMatrix(WeightType **ma,int num)
{
	for( int i = 0; i < num ; i++ )
	    delete[] ma[i];
	delete[] ma;
}

languages: Markdown C++ Batchfile C


text:
<repo_name>atbuwenbo/HackRice<file_sep>/.svn/pristine/e0/e0e1a7fae07e79ee35970f9daecb0b7e5534b581.svn-base
package com.cuter.activity;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.cuter.img.ImageTools;

public class MemeActivity extends BaseActivity {

	private ImageView imgView;

	private Bitmap originalBm;

	private Bitmap result;

	private Button confirm;

	private Button cancel;

	private RelativeLayout memeResult;

	private ImageView memeImg;

	private EditText top;

	private EditText bottom;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_meme);

		Bundle bundle = getIntent().getExtras();

		originalBm = (Bitmap)bundle.get("img");

		initComponent();
		setComponentListener();
	}

	@Override
	public void initComponent() {
		imgView = (ImageView) findViewById(R.id.meme_img);
		imgView.setImageBitmap(originalBm);

		confirm = (Button) findViewById(R.id.meme_confirm);

		cancel = (Button) findViewById(R.id.meme_cancel);

		memeResult = (RelativeLayout) findViewById(R.id.meme_result);

		memeImg = (ImageView) findViewById(R.id.meme_img_result);

		top = (EditText) findViewById(R.id.top_text);
		top.setDrawingCacheEnabled(true);

		bottom = (EditText) findViewById(R.id.bottom_text);
		bottom.setDrawingCacheEnabled(true);
	}

	@Override
	public void setComponentListener() {
		confirm.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {

				int width = getWindowManager().getDefaultDisplay().getWidth();
		        int height = getWindowManager().getDefaultDisplay().getHeight();

		        result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
		        Canvas comboImage = new Canvas(result);

		        originalBm = Bitmap.createScaledBitmap(originalBm, width, height, true);
		        comboImage.drawBitmap(originalBm, 0, 0, null);
				if(!top.getText().equals("")){
					 Bitmap bmp = Bitmap.createBitmap(top.getDrawingCache());
				     comboImage.drawBitmap(bmp, width/2 - bmp.getWidth()/2, 0, null);
				}

				if(!bottom.getText().equals("")){
					 Bitmap bmp = Bitmap.createBitmap(bottom.getDrawingCache());
				     comboImage.drawBitmap(bmp, width/2 - bmp.getWidth()/2, height - bmp.getHeight() - 100, null);
				}

				ImageTools.savePhotoToSDCard(result, Environment.getExternalStorageDirectory().getAbsolutePath() + "/Cuter",
						String.valueOf(System.currentTimeMillis()));
				Toast.makeText(getApplicationContext(), "Storage succeed!", 1000).show();

				memeResult.setVisibility(View.VISIBLE);
				memeImg.setImageBitmap(result);
			}

		});

		memeImg.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				activityJump(SourceSelActivity.class);
			}

		});

		cancel.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				onBackPressed();
			}

		});
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
	}
}
<file_sep>/.svn/pristine/c9/c968aff661e66d9361a155751ff10e2bdcd488a5.svn-base
eclipse.preferences.version=1
encoding//src/com/cuter/activity/BaseActivity.java=UTF-8
encoding/<project>=UTF-8
<file_sep>/.svn/pristine/24/2425f1b394e606b1246a3d9984485298925e925f.svn-base
package com.cuter.img;
public class ColorRange {

	/**
	 * Color[] testc = new Color[8];
	 * testc = new ColorRange().HelloKittyColor();
	 *
	 */

	final Color[] HelloKittyColor(){
		Color [] result = new Color[8];
		result[0] = new Color(255,255,255);
		result[1] = new Color(255,228,196);
		result[2] = new Color(255,182,193);
		result[3] = new Color(255,105,180);
		result[4] = new Color(255,0,0);
		result[5] = new Color(255,0,0);
		result[6] = new Color(30,30,30);
		result[7] = new Color(0,0,0);

		return result;
	}

	final Color[] TransformerColor(){
		Color [] result = new Color[8];
		result[0] = new Color(253,245,230);
		result[1] = new Color(253,245,230);
		result[2] = new Color(95,158,160);
		result[3] = new Color(95,158,160);
		result[4] = new Color(220,20,60);
		result[5] = new Color(220,20,60);
		result[6] = new Color(25,25,112);
		result[7] = new Color(25,25,112);
		return result;
	}

	final Color[] BatmanColor(){
		Color [] result = new Color[8];
		result[0] = new Color(255,250,205);
		result[1] = new Color(255,250,205);
		result[2] = new Color(255,215,0);
		result[3] = new Color(255,215,0);
		result[4] = new Color(0,0,205);
		result[5] = new Color(75,0,130);
		result[6] = new Color(20,20,20);
		result[7] = new Color(0,0,0);
		return result;
	}

	final Color[] CheGuevaraColor(){
		Color [] result = new Color[8];
		result[0] = new Color(255,255,255);
		result[1] = new Color(255,255,255);
		result[2] = new Color(255,255,255);
		result[3] = new Color(255,255,255);
		result[4] = new Color(255,0,0);
		result[5] = new Color(255,0,0);
		result[6] = new Color(0,0,0);
		result[7] = new Color(0,0,0);
		return result;
	}

}
<file_sep>/.svn/pristine/e9/e9378319931eb4e9d41b824f4e8b8e3c0eb52040.svn-base
package com.cuter.activity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.cuter.img.BilateralFilter;
import com.cuter.img.ImageTools;
import com.cuter.util.AppExit;
import com.cuter.util.ThreadPoolUtil;

public class SourceSelActivity extends BaseActivity {

	private ImageButton photoChoiceBtn;

	private ImageView photoView;

	private Bitmap originalBitmap;

	private Bitmap processedBitmap = null;

	private Button rechoose;

	private Button meme;

	private Button compare;

	private GestureDetector sGestureDetector;

	private String imgPath;

	private LinearLayout bottom;

	private RelativeLayout navigation;

	private AbsoluteLayout styles;

	private LinearLayout style1;

	private LinearLayout style2;

	private LinearLayout style3;

	private LinearLayout style4;

	private LinearLayout style5;

	private RelativeLayout pbLayout;

	private BilateralFilter filter;

	private int currentX = 0;

	private MarginLayoutParams params;

	private Handler handler = new Handler(){

		@Override
		public void handleMessage(Message msg){
			photoView.setImageBitmap(processedBitmap);
			pbLayout.setVisibility(View.GONE);
			Log.e("msg", msg.what + "");
		}
	};

	private ProgressBar pb;

	private static final int TAKE_PICTURE = 0;
	private static final int CHOOSE_PICTURE = 1;
	private static final int CROP = 2;
	private static final int SCALE = 2;

	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_source_sel);

		sGestureDetector = new GestureDetector(new StyleGestureListener());
		filter = new BilateralFilter();
		initComponent();
		setComponentListener();
	}

	@SuppressWarnings("deprecation")
	@Override
	public void initComponent() {
		photoChoiceBtn = (ImageButton) findViewById(R.id.photo_choice_btn);
		photoView = (ImageView) findViewById(R.id.photo_view);

		rechoose = (Button) findViewById(R.id.rechoose);
		compare = (Button) findViewById(R.id.compare);
		meme = (Button) findViewById(R.id.meme);
		pbLayout = (RelativeLayout) findViewById(R.id.pb_layout);
		pb = (ProgressBar) findViewById(R.id.img_pb);
		pb.setIndeterminate(false);

		navigation = (RelativeLayout) findViewById(R.id.navigation);
		style1 = (LinearLayout) findViewById(R.id.style1);
		style2 = (LinearLayout) findViewById(R.id.style2);
		style3 = (LinearLayout) findViewById(R.id.style3);
		style4 = (LinearLayout) findViewById(R.id.style4);
		style5 = (LinearLayout) findViewById(R.id.style5);

		bottom = (LinearLayout) findViewById(R.id.bottom);
		styles = (AbsoluteLayout) findViewById(R.id.styles);
	}

	@Override
	public void setComponentListener(){
		photoChoiceBtn.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				showPicturePicker(SourceSelActivity.this, false);
			}

		});

		rechoose.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				photoChoiceBtn.setVisibility(View.VISIBLE);
				photoView.setVisibility(View.INVISIBLE);
				navigation.setVisibility(View.GONE);
			}

		});

		compare.setOnTouchListener(new OnTouchListener(){

			@SuppressLint("ClickableViewAccessibility")
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				int action = event.getAction();
				if(v.getId() == R.id.compare){
					switch(action){
						case MotionEvent.ACTION_DOWN:
							photoView.setImageBitmap(originalBitmap);
							break;
						case MotionEvent.ACTION_UP:
							photoView.setImageBitmap(processedBitmap);
							break;
					}
				}
				return true;
			}

		});

		bottom.setOnTouchListener(new OnTouchListener(){

			@SuppressLint("ClickableViewAccessibility")
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if(v.getId() == R.id.bottom){
					sGestureDetector.onTouchEvent(event);
				}
				return true;
			}

		});

		style1.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				pbLayout.setVisibility(View.VISIBLE);
				pb.setProgress(0);
				ThreadPoolUtil.execute(new Runnable(){

					@Override
					public void run() {
						processedBitmap = filter.bflt(originalBitmap, 0);
						handler.sendEmptyMessage(0);
					}

				});

			}

		});

		style2.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				pbLayout.setVisibility(View.VISIBLE);
				pb.setProgress(0);
				ThreadPoolUtil.execute(new Runnable(){

					@Override
					public void run() {
						processedBitmap = filter.bflt(originalBitmap, 1);
						handler.sendEmptyMessage(0);
					}

				});

			}

		});

		style3.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				pbLayout.setVisibility(View.VISIBLE);
				pb.setProgress(0);
				ThreadPoolUtil.execute(new Runnable(){

					@Override
					public void run() {
						processedBitmap = filter.bflt(originalBitmap, 2);
						handler.sendEmptyMessage(0);
					}

				});

			}

		});

		style4.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				pbLayout.setVisibility(View.VISIBLE);
				pb.setProgress(0);
				ThreadPoolUtil.execute(new Runnable(){

					@Override
					public void run() {
						processedBitmap = filter.bflt(originalBitmap, 3);
						handler.sendEmptyMessage(0);
					}

				});

			}

		});

		style5.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				pbLayout.setVisibility(View.VISIBLE);
				pb.setProgress(0);
				ThreadPoolUtil.execute(new Runnable(){

					@Override
					public void run() {
						processedBitmap = filter.bflt(originalBitmap, 4);
						handler.sendEmptyMessage(0);
					}

				});

			}

		});

		meme.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(SourceSelActivity.this, MemeActivity.class);
				intent.putExtra("img", processedBitmap);
				startActivity(intent);
			}

		});

		photoView.setOnLongClickListener(new OnLongClickListener(){

			@Override
			public boolean onLongClick(View v) {
					AlertDialog.Builder builder = new AlertDialog.Builder(SourceSelActivity.this);
					builder.setNegativeButton("Cancel", null);
					builder.setTitle("What to do?");
					builder.setItems(new String[]{"Share to...", "Save it!"},  new DialogInterface.OnClickListener(){

						@Override
						public void onClick(DialogInterface dialog, int which) {
							switch(which){
							case 0:
								activityJump(LoginActivity.class);
								break;
							case 1:
						 		ImageTools.savePhotoToSDCard(processedBitmap, Environment.getExternalStorageDirectory().getAbsolutePath()+ "/Cuter",
						 				String.valueOf(System.currentTimeMillis()));
						 		Toast.makeText(getApplicationContext(),
						 				"Storage succeed" + Environment.getExternalStorageDirectory().getAbsolutePath() + " /Cuter", 1000).show();
								break;
							}
						}

					});
				builder.create().show();
				return true;
			}

		});
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data){

		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case TAKE_PICTURE:
				imgPath = Environment.getExternalStorageDirectory()+"/image.jpg";
				Bitmap bitmap = BitmapFactory.decodeFile(imgPath);
				Bitmap newBitmap = ImageTools.zoomBitmap(bitmap, bitmap.getWidth() / SCALE, bitmap.getHeight() / SCALE);
				bitmap.recycle();

				originalBitmap = newBitmap;
				photoView.setImageBitmap(newBitmap);
				photoChoiceBtn.setVisibility(View.INVISIBLE);
				photoView.setVisibility(View.VISIBLE);
				navigation.setVisibility(View.VISIBLE);

				imgPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Cuter" + String.valueOf(System.currentTimeMillis());
		 		ImageTools.savePhotoToSDCard(newBitmap, imgPath, String.valueOf(System.currentTimeMillis()));

				break;

			case CHOOSE_PICTURE:
				ContentResolver resolver = getContentResolver();
				Uri originalUri = data.getData();
	            try {
					Bitmap photo = MediaStore.Images.Media.getBitmap(resolver, originalUri);
					if (photo != null) {
						Bitmap smallBitmap = ImageTools.zoomBitmap(photo, photo.getWidth() / SCALE, photo.getHeight() / SCALE);
						photo.recycle();

						originalBitmap = smallBitmap;
						photoView.setImageBitmap(smallBitmap);
						photoView.setVisibility(View.VISIBLE);
						navigation.setVisibility(View.VISIBLE);
					}
				} catch (FileNotFoundException e) {
				    e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				}
				break;

			default:
				break;
			}
		}

	}

	@SuppressLint("WorldWriteableFiles")
	public void showPicturePicker(Context context,boolean isCrop){
		final boolean crop = isCrop;
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setTitle("Cuter, make the art");
		builder.setNegativeButton("Cancel", null);
		builder.setItems(new String[]{"Use Camera","Select Photo"}, new DialogInterface.OnClickListener() {
			int REQUEST_CODE;

			@Override
			public void onClick(DialogInterface dialog, int which) {
				switch (which) {
				case TAKE_PICTURE:
					Uri imageUri = null;
					String fileName = null;
					Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
					if (crop) {
						REQUEST_CODE = CROP;
						SharedPreferences sharedPreferences = getSharedPreferences("temp",Context.MODE_WORLD_WRITEABLE);
						ImageTools.deletePhotoAtPathAndName(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Cuter", sharedPreferences.getString("tempName", ""));

						fileName = String.valueOf(System.currentTimeMillis()) + ".jpg";
						Editor editor = sharedPreferences.edit();
						editor.putString("tempName", fileName);
						editor.commit();
					}else {
						REQUEST_CODE = TAKE_PICTURE;
						fileName = "image.jpg";
					}
					imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),fileName));
					openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
					startActivityForResult(openCameraIntent, REQUEST_CODE);
					break;

				case CHOOSE_PICTURE:
					Intent openAlbumIntent = new Intent(Intent.ACTION_GET_CONTENT);
					if (crop) {
						REQUEST_CODE = CROP;
					}else {
						REQUEST_CODE = CHOOSE_PICTURE;
					}
					openAlbumIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
					startActivityForResult(openAlbumIntent, REQUEST_CODE);
					break;

				default:
					break;
				}
			}
		});
		builder.create().show();
	}

	class StyleGestureListener extends SimpleOnGestureListener {

		 @Override
		 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//		       		Log.e("Scrolling", distanceX +", " + distanceY);
		       		params = new MarginLayoutParams(styles.getLayoutParams());
		       		params.setMargins(currentX, params.topMargin, currentX + params.width, params.bottomMargin);
		       		currentX -= distanceX;
		       		LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(params);
		       		styles.setLayoutParams(newParams);
		       		return false;
		         }

		 @Override
		 public boolean onFling(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
	    			Log.e("Flinging", distanceX +", " + distanceY);

	    			return false;
		         }

	}

	@Override
	public void onBackPressed() {
		  android.content.DialogInterface.OnClickListener exit
				= new android.content.DialogInterface.OnClickListener()
				{
					@Override
					public void onClick(DialogInterface arg0, int arg1)
					{
						AppExit.getInstance().onTerminate();
					}
				};
			new AlertDialog.Builder(this)
			.setTitle("Exit？")
			.setMessage("Confirmation of exit")
			.setPositiveButton("Confirm", exit)
			.setNegativeButton("Back", null)
			.show();

	}

}
<file_sep>/src/com/cuter/activity/BaseActivity.java
package com.cuter.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.cuter.util.AppExit;

public abstract class BaseActivity extends Activity {
	  @Override
	   protected void onCreate(Bundle savedInstanceState) {
	       super.onCreate(savedInstanceState);  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);  //全屏
	       requestWindowFeature(Window.FEATURE_NO_TITLE);
	       AppExit.getInstance().addActivity(this);

	   }

	  @Override
	  public void onBackPressed(){
		  super.onBackPressed();
	  }

	  @Override
	  public void onResume(){
		  super.onResume();
	  }

	  @Override
	  public void onPause(){
		  super.onPause();
		  // Logs 'app deactivate' App Event.
	  }

	  public void activityJump(Class<?> activity){
		  Intent intent = new Intent(this, activity);
		  startActivity(intent);
	  }

	  public abstract void initComponent();

	  public abstract void setComponentListener();
}

branch_name: refs/heads/master

languages: Java INI

repo_language: Java

repo_name: atbuwenbo/HackRice