prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>dummy_operator.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. from airflow.models import BaseOperator from airflow.utils.decorators import apply_defaults class DummyOperator(BaseOperator): """ Operator that does literally nothing. It can be used to group tasks in a DAG. """ ui_color = '#e8f7e4' @apply_defaults def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) def execute(self, context): <|fim_middle|> <|fim▁end|>
pass
<|file_name|>dummy_operator.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. from airflow.models import BaseOperator from airflow.utils.decorators import apply_defaults class DummyOperator(BaseOperator): """ Operator that does literally nothing. It can be used to group tasks in a DAG. """ ui_color = '#e8f7e4' @apply_defaults def <|fim_middle|>(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) def execute(self, context): pass <|fim▁end|>
__init__
<|file_name|>dummy_operator.py<|end_file_name|><|fim▁begin|># # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. from airflow.models import BaseOperator from airflow.utils.decorators import apply_defaults class DummyOperator(BaseOperator): """ Operator that does literally nothing. It can be used to group tasks in a DAG. """ ui_color = '#e8f7e4' @apply_defaults def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) def <|fim_middle|>(self, context): pass <|fim▁end|>
execute
<|file_name|>guimporter.py<|end_file_name|><|fim▁begin|>#guimporter.py import sys from PySide import QtGui, QtCore, QtWebKit<|fim▁hole|><|fim▁end|>
Signal = QtCore.Signal
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1<|fim▁hole|>#python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
#notes :
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): <|fim_middle|> MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
tour=list(range(tour_length)) random.shuffle(tour) return tour
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): <|fim_middle|> def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
'''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): <|fim_middle|> def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
T = start_temp while True: yield T T = alpha * T
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): <|fim_middle|> class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature )
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: <|fim_middle|> def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
'''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): <|fim_middle|> def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
self.objective_function=objective_function self.best=None self.best_score=None
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): <|fim_middle|> def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) <|fim_middle|> def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best)
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): <|fim_middle|> if __name__ == "__main__": SolveTSP();<|fim▁end|>
print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png");
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: <|fim_middle|> def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: <|fim_middle|> else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
copy[i:j+1]=reversed(tour[i:j+1])
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: <|fim_middle|> if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:])
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour <|fim_middle|> def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
yield copy
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: <|fim_middle|> else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
return 1.0
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: <|fim_middle|> class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
return math.exp( -abs(next_score-prev_score)/temperature )
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: <|fim_middle|> return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
self.best_score=score self.best=solution
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: <|fim_middle|> next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
done=True break
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: <|fim_middle|> # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
current = next current_score= next_score break
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: <|fim_middle|> best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
break
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": <|fim_middle|> <|fim▁end|>
SolveTSP();
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def <|fim_middle|>(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
GenerateInitialPath
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def <|fim_middle|>(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
reversed_sections
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def <|fim_middle|>(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
kirkpatrick_cooling
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def <|fim_middle|>(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
P
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def <|fim_middle|>(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
__init__
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def <|fim_middle|>(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
__call__
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def <|fim_middle|>(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def SolveTSP(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
ApplySimulatedAnnealing
<|file_name|>SolveTSPSimulatedAnnealing.py<|end_file_name|><|fim▁begin|>#============================================================================== #description : Solves travelling salesman problem by using Hill Climbing. #author : Yakup Cengiz #date : 20151121 #version : 0.1 #notes : #python_version : 3.5.0 #Reference : http://www.psychicorigami.com/category/tsp/ #============================================================================== import math import sys import os import random CommonPath = os.path.abspath(os.path.join('..', 'Common')) sys.path.append(CommonPath) import tsp def GenerateInitialPath(tour_length): tour=list(range(tour_length)) random.shuffle(tour) return tour MAX_ITERATION = 50000 def reversed_sections(tour): '''generator to return all possible variations where the section between two cities are swapped''' for i,j in tsp.AllEdges(len(tour)): if i != j: copy=tour[:] if i < j: copy[i:j+1]=reversed(tour[i:j+1]) else: copy[i+1:]=reversed(tour[:j]) copy[:j]=reversed(tour[i+1:]) if copy != tour: # no point returning the same tour yield copy def kirkpatrick_cooling(start_temp, alpha): T = start_temp while True: yield T T = alpha * T def P(prev_score,next_score,temperature): if next_score > prev_score: return 1.0 else: return math.exp( -abs(next_score-prev_score)/temperature ) class ObjectiveFunction: '''class to wrap an objective function and keep track of the best solution evaluated''' def __init__(self,objective_function): self.objective_function=objective_function self.best=None self.best_score=None def __call__(self,solution): score=self.objective_function(solution) if self.best is None or score > self.best_score: self.best_score=score self.best=solution return score def ApplySimulatedAnnealing(init_function,move_operator,objective_function,max_evaluations,start_temp,alpha): # wrap the objective function (so we record the best) objective_function=ObjectiveFunction(objective_function) current = init_function() current_score = objective_function(current) iterationCount = 1 cooling_schedule = kirkpatrick_cooling(start_temp, alpha) for temperature in cooling_schedule: done = False # examine moves around our current position for next in move_operator(current): if iterationCount >= max_evaluations: done=True break next_score=objective_function(next) iterationCount+=1 # probablistically accept this solution always accepting better solutions p = P(current_score, next_score, temperature) # random.random() basic function random() generates a random float uniformly in the range [0.0, 1.0). # p function returns data in range [0.0, 1.0] if random.random() < p: current = next current_score= next_score break # see if completely finished if done: break best_score = objective_function.best_score best = objective_function.best return (iterationCount,best_score,best) def <|fim_middle|>(): print("Starting to solve travel salesman problem") coordinates = tsp.ReadCoordinatesFromFile(".\cityCoordinates.csv") distance_matrix = tsp.ComputeDistanceMatrix(coordinates); init_function = lambda: GenerateInitialPath(len(coordinates)) objective_function = lambda tour: -tsp.ComputeTourLength(distance_matrix, tour) start_temp,alpha = 100, 0.995 iterationCount,best_score,shortestPath = ApplySimulatedAnnealing(init_function, reversed_sections, objective_function, MAX_ITERATION,start_temp,alpha) print(iterationCount, best_score, shortestPath); tsp.DrawPath(coordinates, shortestPath, "TSP.png"); if __name__ == "__main__": SolveTSP();<|fim▁end|>
SolveTSP
<|file_name|>print_MODFLOW_inputs_res_NWT.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Sun Sep 17 22:06:52 2017 Based on: print_MODFLOW_inputs_res_NWT.m @author: gcng """ # print_MODFLOW_inputs import numpy as np import MODFLOW_NWT_lib as mf # functions to write individual MODFLOW files import os # os functions from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') LOCAL_DIR = parser.get('settings', 'local_dir') GSFLOW_DIR = LOCAL_DIR + "/GSFLOW" <|fim▁hole|> # - directories sw_2005_NWT = 2 # 1 for MODFLOW-2005; 2 for MODFLOW-NWT algorithm (both can be # carried out with MODFLOW-NWT code) fl_BoundConstH = 0 # 1 for const head at high elev boundary, needed for numerical # convergence for AGU2016 poster. Maybe resolved with MODFLOW-NWT? if sw_2005_NWT == 1: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_2005/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_2005/' elif sw_2005_NWT == 2: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_NWT/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_NWT/' infile_pre = 'test2lay_py'; NLAY = 2; DZ = [100, 50] # [NLAYx1] [m] ***testing # DZ = [350, 100] # [NLAYx1] [m] ***testing # length of transient stress period (follows 1-day steady-state period) [d] # perlen_tr = 365; # [d], ok if too long # perlen_tr = 365*5 + ceil(365*5/4); # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) perlen_tr = 365*30 + np.ceil(365*30/4) # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) GIS_indir = GSFLOW_DIR + '/DataToReadIn/GIS/'; # use restart file as initial cond (empty string to not use restart file) fil_res_in = '' # empty string to not use restart file #fil_res_in = '/home/gcng/workspace/Pfil_res_inrojectFiles/AndesWaterResources/GSFLOW/outputs/MODFLOW/test2lay_melt_30yr.out' % empty string to not use restart file # for various files: ba6, dis, uzf, lpf surfz_fil = GIS_indir + 'topo.asc' # surfz_fil = GIS_indir + 'SRTM_new_20161208.asc' # for various files: ba6, uzf mask_fil = GIS_indir + 'basinmask_dischargept.asc' # for sfr reach_fil = GIS_indir + 'reach_data.txt' segment_fil_all = [GIS_indir + 'segment_data_4A_INFORMATION_Man.csv', GIS_indir + 'segment_data_4B_UPSTREAM_Man.csv', GIS_indir + 'segment_data_4C_DOWNSTREAM_Man.csv'] # create MODFLOW input directory if it does not exist: if not os.path.isdir(GSFLOW_indir): os.makedirs(GSFLOW_indir) # while we're at it, create MODFLOW output file if it does not exist: if not os.path.isdir(GSFLOW_outdir): os.makedirs(GSFLOW_outdir) ## mf.write_dis_MOD2_f(GSFLOW_indir, infile_pre, surfz_fil, NLAY, DZ, perlen_tr); mf.write_ba6_MOD3_2(GSFLOW_indir, infile_pre, mask_fil, fl_BoundConstH); # list this below write_dis_MOD2_f # flow algorithm if sw_2005_NWT == 1: mf.write_lpf_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); elif sw_2005_NWT == 2: # MODFLOW-NWT files mf.write_upw_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); mf.NWT_write_file(GSFLOW_indir, infile_pre); # unsat zone and streamflow input files mf.make_uzf3_f_2(GSFLOW_indir, infile_pre, surfz_fil, mask_fil); mf.make_sfr2_f_Mannings(GSFLOW_indir, infile_pre, reach_fil, segment_fil_all); # list this below write_dis_MOD2_f # Write PCG file (only used for MODFLOW-2005, but this function also creates OC file) mf.write_OC_PCG_MOD_f(GSFLOW_indir, infile_pre, perlen_tr); # Write namefile mf.write_nam_MOD_f2_NWT(GSFLOW_indir, GSFLOW_outdir, infile_pre, fil_res_in, sw_2005_NWT);<|fim▁end|>
<|file_name|>print_MODFLOW_inputs_res_NWT.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Sun Sep 17 22:06:52 2017 Based on: print_MODFLOW_inputs_res_NWT.m @author: gcng """ # print_MODFLOW_inputs import numpy as np import MODFLOW_NWT_lib as mf # functions to write individual MODFLOW files import os # os functions from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') LOCAL_DIR = parser.get('settings', 'local_dir') GSFLOW_DIR = LOCAL_DIR + "/GSFLOW" # - directories sw_2005_NWT = 2 # 1 for MODFLOW-2005; 2 for MODFLOW-NWT algorithm (both can be # carried out with MODFLOW-NWT code) fl_BoundConstH = 0 # 1 for const head at high elev boundary, needed for numerical # convergence for AGU2016 poster. Maybe resolved with MODFLOW-NWT? if sw_2005_NWT == 1: # MODFLOW input files <|fim_middle|> elif sw_2005_NWT == 2: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_NWT/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_NWT/' infile_pre = 'test2lay_py'; NLAY = 2; DZ = [100, 50] # [NLAYx1] [m] ***testing # DZ = [350, 100] # [NLAYx1] [m] ***testing # length of transient stress period (follows 1-day steady-state period) [d] # perlen_tr = 365; # [d], ok if too long # perlen_tr = 365*5 + ceil(365*5/4); # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) perlen_tr = 365*30 + np.ceil(365*30/4) # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) GIS_indir = GSFLOW_DIR + '/DataToReadIn/GIS/'; # use restart file as initial cond (empty string to not use restart file) fil_res_in = '' # empty string to not use restart file #fil_res_in = '/home/gcng/workspace/Pfil_res_inrojectFiles/AndesWaterResources/GSFLOW/outputs/MODFLOW/test2lay_melt_30yr.out' % empty string to not use restart file # for various files: ba6, dis, uzf, lpf surfz_fil = GIS_indir + 'topo.asc' # surfz_fil = GIS_indir + 'SRTM_new_20161208.asc' # for various files: ba6, uzf mask_fil = GIS_indir + 'basinmask_dischargept.asc' # for sfr reach_fil = GIS_indir + 'reach_data.txt' segment_fil_all = [GIS_indir + 'segment_data_4A_INFORMATION_Man.csv', GIS_indir + 'segment_data_4B_UPSTREAM_Man.csv', GIS_indir + 'segment_data_4C_DOWNSTREAM_Man.csv'] # create MODFLOW input directory if it does not exist: if not os.path.isdir(GSFLOW_indir): os.makedirs(GSFLOW_indir) # while we're at it, create MODFLOW output file if it does not exist: if not os.path.isdir(GSFLOW_outdir): os.makedirs(GSFLOW_outdir) ## mf.write_dis_MOD2_f(GSFLOW_indir, infile_pre, surfz_fil, NLAY, DZ, perlen_tr); mf.write_ba6_MOD3_2(GSFLOW_indir, infile_pre, mask_fil, fl_BoundConstH); # list this below write_dis_MOD2_f # flow algorithm if sw_2005_NWT == 1: mf.write_lpf_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); elif sw_2005_NWT == 2: # MODFLOW-NWT files mf.write_upw_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); mf.NWT_write_file(GSFLOW_indir, infile_pre); # unsat zone and streamflow input files mf.make_uzf3_f_2(GSFLOW_indir, infile_pre, surfz_fil, mask_fil); mf.make_sfr2_f_Mannings(GSFLOW_indir, infile_pre, reach_fil, segment_fil_all); # list this below write_dis_MOD2_f # Write PCG file (only used for MODFLOW-2005, but this function also creates OC file) mf.write_OC_PCG_MOD_f(GSFLOW_indir, infile_pre, perlen_tr); # Write namefile mf.write_nam_MOD_f2_NWT(GSFLOW_indir, GSFLOW_outdir, infile_pre, fil_res_in, sw_2005_NWT); <|fim▁end|>
GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_2005/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_2005/'
<|file_name|>print_MODFLOW_inputs_res_NWT.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Sun Sep 17 22:06:52 2017 Based on: print_MODFLOW_inputs_res_NWT.m @author: gcng """ # print_MODFLOW_inputs import numpy as np import MODFLOW_NWT_lib as mf # functions to write individual MODFLOW files import os # os functions from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') LOCAL_DIR = parser.get('settings', 'local_dir') GSFLOW_DIR = LOCAL_DIR + "/GSFLOW" # - directories sw_2005_NWT = 2 # 1 for MODFLOW-2005; 2 for MODFLOW-NWT algorithm (both can be # carried out with MODFLOW-NWT code) fl_BoundConstH = 0 # 1 for const head at high elev boundary, needed for numerical # convergence for AGU2016 poster. Maybe resolved with MODFLOW-NWT? if sw_2005_NWT == 1: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_2005/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_2005/' elif sw_2005_NWT == 2: # MODFLOW input files <|fim_middle|> infile_pre = 'test2lay_py'; NLAY = 2; DZ = [100, 50] # [NLAYx1] [m] ***testing # DZ = [350, 100] # [NLAYx1] [m] ***testing # length of transient stress period (follows 1-day steady-state period) [d] # perlen_tr = 365; # [d], ok if too long # perlen_tr = 365*5 + ceil(365*5/4); # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) perlen_tr = 365*30 + np.ceil(365*30/4) # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) GIS_indir = GSFLOW_DIR + '/DataToReadIn/GIS/'; # use restart file as initial cond (empty string to not use restart file) fil_res_in = '' # empty string to not use restart file #fil_res_in = '/home/gcng/workspace/Pfil_res_inrojectFiles/AndesWaterResources/GSFLOW/outputs/MODFLOW/test2lay_melt_30yr.out' % empty string to not use restart file # for various files: ba6, dis, uzf, lpf surfz_fil = GIS_indir + 'topo.asc' # surfz_fil = GIS_indir + 'SRTM_new_20161208.asc' # for various files: ba6, uzf mask_fil = GIS_indir + 'basinmask_dischargept.asc' # for sfr reach_fil = GIS_indir + 'reach_data.txt' segment_fil_all = [GIS_indir + 'segment_data_4A_INFORMATION_Man.csv', GIS_indir + 'segment_data_4B_UPSTREAM_Man.csv', GIS_indir + 'segment_data_4C_DOWNSTREAM_Man.csv'] # create MODFLOW input directory if it does not exist: if not os.path.isdir(GSFLOW_indir): os.makedirs(GSFLOW_indir) # while we're at it, create MODFLOW output file if it does not exist: if not os.path.isdir(GSFLOW_outdir): os.makedirs(GSFLOW_outdir) ## mf.write_dis_MOD2_f(GSFLOW_indir, infile_pre, surfz_fil, NLAY, DZ, perlen_tr); mf.write_ba6_MOD3_2(GSFLOW_indir, infile_pre, mask_fil, fl_BoundConstH); # list this below write_dis_MOD2_f # flow algorithm if sw_2005_NWT == 1: mf.write_lpf_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); elif sw_2005_NWT == 2: # MODFLOW-NWT files mf.write_upw_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); mf.NWT_write_file(GSFLOW_indir, infile_pre); # unsat zone and streamflow input files mf.make_uzf3_f_2(GSFLOW_indir, infile_pre, surfz_fil, mask_fil); mf.make_sfr2_f_Mannings(GSFLOW_indir, infile_pre, reach_fil, segment_fil_all); # list this below write_dis_MOD2_f # Write PCG file (only used for MODFLOW-2005, but this function also creates OC file) mf.write_OC_PCG_MOD_f(GSFLOW_indir, infile_pre, perlen_tr); # Write namefile mf.write_nam_MOD_f2_NWT(GSFLOW_indir, GSFLOW_outdir, infile_pre, fil_res_in, sw_2005_NWT); <|fim▁end|>
GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_NWT/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_NWT/'
<|file_name|>print_MODFLOW_inputs_res_NWT.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Sun Sep 17 22:06:52 2017 Based on: print_MODFLOW_inputs_res_NWT.m @author: gcng """ # print_MODFLOW_inputs import numpy as np import MODFLOW_NWT_lib as mf # functions to write individual MODFLOW files import os # os functions from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') LOCAL_DIR = parser.get('settings', 'local_dir') GSFLOW_DIR = LOCAL_DIR + "/GSFLOW" # - directories sw_2005_NWT = 2 # 1 for MODFLOW-2005; 2 for MODFLOW-NWT algorithm (both can be # carried out with MODFLOW-NWT code) fl_BoundConstH = 0 # 1 for const head at high elev boundary, needed for numerical # convergence for AGU2016 poster. Maybe resolved with MODFLOW-NWT? if sw_2005_NWT == 1: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_2005/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_2005/' elif sw_2005_NWT == 2: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_NWT/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_NWT/' infile_pre = 'test2lay_py'; NLAY = 2; DZ = [100, 50] # [NLAYx1] [m] ***testing # DZ = [350, 100] # [NLAYx1] [m] ***testing # length of transient stress period (follows 1-day steady-state period) [d] # perlen_tr = 365; # [d], ok if too long # perlen_tr = 365*5 + ceil(365*5/4); # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) perlen_tr = 365*30 + np.ceil(365*30/4) # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) GIS_indir = GSFLOW_DIR + '/DataToReadIn/GIS/'; # use restart file as initial cond (empty string to not use restart file) fil_res_in = '' # empty string to not use restart file #fil_res_in = '/home/gcng/workspace/Pfil_res_inrojectFiles/AndesWaterResources/GSFLOW/outputs/MODFLOW/test2lay_melt_30yr.out' % empty string to not use restart file # for various files: ba6, dis, uzf, lpf surfz_fil = GIS_indir + 'topo.asc' # surfz_fil = GIS_indir + 'SRTM_new_20161208.asc' # for various files: ba6, uzf mask_fil = GIS_indir + 'basinmask_dischargept.asc' # for sfr reach_fil = GIS_indir + 'reach_data.txt' segment_fil_all = [GIS_indir + 'segment_data_4A_INFORMATION_Man.csv', GIS_indir + 'segment_data_4B_UPSTREAM_Man.csv', GIS_indir + 'segment_data_4C_DOWNSTREAM_Man.csv'] # create MODFLOW input directory if it does not exist: if not os.path.isdir(GSFLOW_indir): <|fim_middle|> # while we're at it, create MODFLOW output file if it does not exist: if not os.path.isdir(GSFLOW_outdir): os.makedirs(GSFLOW_outdir) ## mf.write_dis_MOD2_f(GSFLOW_indir, infile_pre, surfz_fil, NLAY, DZ, perlen_tr); mf.write_ba6_MOD3_2(GSFLOW_indir, infile_pre, mask_fil, fl_BoundConstH); # list this below write_dis_MOD2_f # flow algorithm if sw_2005_NWT == 1: mf.write_lpf_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); elif sw_2005_NWT == 2: # MODFLOW-NWT files mf.write_upw_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); mf.NWT_write_file(GSFLOW_indir, infile_pre); # unsat zone and streamflow input files mf.make_uzf3_f_2(GSFLOW_indir, infile_pre, surfz_fil, mask_fil); mf.make_sfr2_f_Mannings(GSFLOW_indir, infile_pre, reach_fil, segment_fil_all); # list this below write_dis_MOD2_f # Write PCG file (only used for MODFLOW-2005, but this function also creates OC file) mf.write_OC_PCG_MOD_f(GSFLOW_indir, infile_pre, perlen_tr); # Write namefile mf.write_nam_MOD_f2_NWT(GSFLOW_indir, GSFLOW_outdir, infile_pre, fil_res_in, sw_2005_NWT); <|fim▁end|>
os.makedirs(GSFLOW_indir)
<|file_name|>print_MODFLOW_inputs_res_NWT.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Sun Sep 17 22:06:52 2017 Based on: print_MODFLOW_inputs_res_NWT.m @author: gcng """ # print_MODFLOW_inputs import numpy as np import MODFLOW_NWT_lib as mf # functions to write individual MODFLOW files import os # os functions from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') LOCAL_DIR = parser.get('settings', 'local_dir') GSFLOW_DIR = LOCAL_DIR + "/GSFLOW" # - directories sw_2005_NWT = 2 # 1 for MODFLOW-2005; 2 for MODFLOW-NWT algorithm (both can be # carried out with MODFLOW-NWT code) fl_BoundConstH = 0 # 1 for const head at high elev boundary, needed for numerical # convergence for AGU2016 poster. Maybe resolved with MODFLOW-NWT? if sw_2005_NWT == 1: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_2005/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_2005/' elif sw_2005_NWT == 2: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_NWT/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_NWT/' infile_pre = 'test2lay_py'; NLAY = 2; DZ = [100, 50] # [NLAYx1] [m] ***testing # DZ = [350, 100] # [NLAYx1] [m] ***testing # length of transient stress period (follows 1-day steady-state period) [d] # perlen_tr = 365; # [d], ok if too long # perlen_tr = 365*5 + ceil(365*5/4); # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) perlen_tr = 365*30 + np.ceil(365*30/4) # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) GIS_indir = GSFLOW_DIR + '/DataToReadIn/GIS/'; # use restart file as initial cond (empty string to not use restart file) fil_res_in = '' # empty string to not use restart file #fil_res_in = '/home/gcng/workspace/Pfil_res_inrojectFiles/AndesWaterResources/GSFLOW/outputs/MODFLOW/test2lay_melt_30yr.out' % empty string to not use restart file # for various files: ba6, dis, uzf, lpf surfz_fil = GIS_indir + 'topo.asc' # surfz_fil = GIS_indir + 'SRTM_new_20161208.asc' # for various files: ba6, uzf mask_fil = GIS_indir + 'basinmask_dischargept.asc' # for sfr reach_fil = GIS_indir + 'reach_data.txt' segment_fil_all = [GIS_indir + 'segment_data_4A_INFORMATION_Man.csv', GIS_indir + 'segment_data_4B_UPSTREAM_Man.csv', GIS_indir + 'segment_data_4C_DOWNSTREAM_Man.csv'] # create MODFLOW input directory if it does not exist: if not os.path.isdir(GSFLOW_indir): os.makedirs(GSFLOW_indir) # while we're at it, create MODFLOW output file if it does not exist: if not os.path.isdir(GSFLOW_outdir): <|fim_middle|> ## mf.write_dis_MOD2_f(GSFLOW_indir, infile_pre, surfz_fil, NLAY, DZ, perlen_tr); mf.write_ba6_MOD3_2(GSFLOW_indir, infile_pre, mask_fil, fl_BoundConstH); # list this below write_dis_MOD2_f # flow algorithm if sw_2005_NWT == 1: mf.write_lpf_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); elif sw_2005_NWT == 2: # MODFLOW-NWT files mf.write_upw_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); mf.NWT_write_file(GSFLOW_indir, infile_pre); # unsat zone and streamflow input files mf.make_uzf3_f_2(GSFLOW_indir, infile_pre, surfz_fil, mask_fil); mf.make_sfr2_f_Mannings(GSFLOW_indir, infile_pre, reach_fil, segment_fil_all); # list this below write_dis_MOD2_f # Write PCG file (only used for MODFLOW-2005, but this function also creates OC file) mf.write_OC_PCG_MOD_f(GSFLOW_indir, infile_pre, perlen_tr); # Write namefile mf.write_nam_MOD_f2_NWT(GSFLOW_indir, GSFLOW_outdir, infile_pre, fil_res_in, sw_2005_NWT); <|fim▁end|>
os.makedirs(GSFLOW_outdir)
<|file_name|>print_MODFLOW_inputs_res_NWT.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Sun Sep 17 22:06:52 2017 Based on: print_MODFLOW_inputs_res_NWT.m @author: gcng """ # print_MODFLOW_inputs import numpy as np import MODFLOW_NWT_lib as mf # functions to write individual MODFLOW files import os # os functions from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') LOCAL_DIR = parser.get('settings', 'local_dir') GSFLOW_DIR = LOCAL_DIR + "/GSFLOW" # - directories sw_2005_NWT = 2 # 1 for MODFLOW-2005; 2 for MODFLOW-NWT algorithm (both can be # carried out with MODFLOW-NWT code) fl_BoundConstH = 0 # 1 for const head at high elev boundary, needed for numerical # convergence for AGU2016 poster. Maybe resolved with MODFLOW-NWT? if sw_2005_NWT == 1: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_2005/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_2005/' elif sw_2005_NWT == 2: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_NWT/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_NWT/' infile_pre = 'test2lay_py'; NLAY = 2; DZ = [100, 50] # [NLAYx1] [m] ***testing # DZ = [350, 100] # [NLAYx1] [m] ***testing # length of transient stress period (follows 1-day steady-state period) [d] # perlen_tr = 365; # [d], ok if too long # perlen_tr = 365*5 + ceil(365*5/4); # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) perlen_tr = 365*30 + np.ceil(365*30/4) # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) GIS_indir = GSFLOW_DIR + '/DataToReadIn/GIS/'; # use restart file as initial cond (empty string to not use restart file) fil_res_in = '' # empty string to not use restart file #fil_res_in = '/home/gcng/workspace/Pfil_res_inrojectFiles/AndesWaterResources/GSFLOW/outputs/MODFLOW/test2lay_melt_30yr.out' % empty string to not use restart file # for various files: ba6, dis, uzf, lpf surfz_fil = GIS_indir + 'topo.asc' # surfz_fil = GIS_indir + 'SRTM_new_20161208.asc' # for various files: ba6, uzf mask_fil = GIS_indir + 'basinmask_dischargept.asc' # for sfr reach_fil = GIS_indir + 'reach_data.txt' segment_fil_all = [GIS_indir + 'segment_data_4A_INFORMATION_Man.csv', GIS_indir + 'segment_data_4B_UPSTREAM_Man.csv', GIS_indir + 'segment_data_4C_DOWNSTREAM_Man.csv'] # create MODFLOW input directory if it does not exist: if not os.path.isdir(GSFLOW_indir): os.makedirs(GSFLOW_indir) # while we're at it, create MODFLOW output file if it does not exist: if not os.path.isdir(GSFLOW_outdir): os.makedirs(GSFLOW_outdir) ## mf.write_dis_MOD2_f(GSFLOW_indir, infile_pre, surfz_fil, NLAY, DZ, perlen_tr); mf.write_ba6_MOD3_2(GSFLOW_indir, infile_pre, mask_fil, fl_BoundConstH); # list this below write_dis_MOD2_f # flow algorithm if sw_2005_NWT == 1: <|fim_middle|> elif sw_2005_NWT == 2: # MODFLOW-NWT files mf.write_upw_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); mf.NWT_write_file(GSFLOW_indir, infile_pre); # unsat zone and streamflow input files mf.make_uzf3_f_2(GSFLOW_indir, infile_pre, surfz_fil, mask_fil); mf.make_sfr2_f_Mannings(GSFLOW_indir, infile_pre, reach_fil, segment_fil_all); # list this below write_dis_MOD2_f # Write PCG file (only used for MODFLOW-2005, but this function also creates OC file) mf.write_OC_PCG_MOD_f(GSFLOW_indir, infile_pre, perlen_tr); # Write namefile mf.write_nam_MOD_f2_NWT(GSFLOW_indir, GSFLOW_outdir, infile_pre, fil_res_in, sw_2005_NWT); <|fim▁end|>
mf.write_lpf_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY);
<|file_name|>print_MODFLOW_inputs_res_NWT.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Created on Sun Sep 17 22:06:52 2017 Based on: print_MODFLOW_inputs_res_NWT.m @author: gcng """ # print_MODFLOW_inputs import numpy as np import MODFLOW_NWT_lib as mf # functions to write individual MODFLOW files import os # os functions from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') LOCAL_DIR = parser.get('settings', 'local_dir') GSFLOW_DIR = LOCAL_DIR + "/GSFLOW" # - directories sw_2005_NWT = 2 # 1 for MODFLOW-2005; 2 for MODFLOW-NWT algorithm (both can be # carried out with MODFLOW-NWT code) fl_BoundConstH = 0 # 1 for const head at high elev boundary, needed for numerical # convergence for AGU2016 poster. Maybe resolved with MODFLOW-NWT? if sw_2005_NWT == 1: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_2005/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_2005/' elif sw_2005_NWT == 2: # MODFLOW input files GSFLOW_indir = GSFLOW_DIR + '/inputs/MODFLOW_NWT/' # MODFLOW output files GSFLOW_outdir = GSFLOW_DIR + '/outputs/MODFLOW_NWT/' infile_pre = 'test2lay_py'; NLAY = 2; DZ = [100, 50] # [NLAYx1] [m] ***testing # DZ = [350, 100] # [NLAYx1] [m] ***testing # length of transient stress period (follows 1-day steady-state period) [d] # perlen_tr = 365; # [d], ok if too long # perlen_tr = 365*5 + ceil(365*5/4); # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) perlen_tr = 365*30 + np.ceil(365*30/4) # [d], includes leap years; ok if too long (I think, but maybe run time is longer?) GIS_indir = GSFLOW_DIR + '/DataToReadIn/GIS/'; # use restart file as initial cond (empty string to not use restart file) fil_res_in = '' # empty string to not use restart file #fil_res_in = '/home/gcng/workspace/Pfil_res_inrojectFiles/AndesWaterResources/GSFLOW/outputs/MODFLOW/test2lay_melt_30yr.out' % empty string to not use restart file # for various files: ba6, dis, uzf, lpf surfz_fil = GIS_indir + 'topo.asc' # surfz_fil = GIS_indir + 'SRTM_new_20161208.asc' # for various files: ba6, uzf mask_fil = GIS_indir + 'basinmask_dischargept.asc' # for sfr reach_fil = GIS_indir + 'reach_data.txt' segment_fil_all = [GIS_indir + 'segment_data_4A_INFORMATION_Man.csv', GIS_indir + 'segment_data_4B_UPSTREAM_Man.csv', GIS_indir + 'segment_data_4C_DOWNSTREAM_Man.csv'] # create MODFLOW input directory if it does not exist: if not os.path.isdir(GSFLOW_indir): os.makedirs(GSFLOW_indir) # while we're at it, create MODFLOW output file if it does not exist: if not os.path.isdir(GSFLOW_outdir): os.makedirs(GSFLOW_outdir) ## mf.write_dis_MOD2_f(GSFLOW_indir, infile_pre, surfz_fil, NLAY, DZ, perlen_tr); mf.write_ba6_MOD3_2(GSFLOW_indir, infile_pre, mask_fil, fl_BoundConstH); # list this below write_dis_MOD2_f # flow algorithm if sw_2005_NWT == 1: mf.write_lpf_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); elif sw_2005_NWT == 2: # MODFLOW-NWT files <|fim_middle|> # unsat zone and streamflow input files mf.make_uzf3_f_2(GSFLOW_indir, infile_pre, surfz_fil, mask_fil); mf.make_sfr2_f_Mannings(GSFLOW_indir, infile_pre, reach_fil, segment_fil_all); # list this below write_dis_MOD2_f # Write PCG file (only used for MODFLOW-2005, but this function also creates OC file) mf.write_OC_PCG_MOD_f(GSFLOW_indir, infile_pre, perlen_tr); # Write namefile mf.write_nam_MOD_f2_NWT(GSFLOW_indir, GSFLOW_outdir, infile_pre, fil_res_in, sw_2005_NWT); <|fim▁end|>
mf.write_upw_MOD2_f2_2(GSFLOW_indir, infile_pre, surfz_fil, NLAY); mf.NWT_write_file(GSFLOW_indir, infile_pre);
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python # coding: utf8 import os import subprocess from '{% if cookiecutter.namespace %}{{ cookiecutter.namespace }}.{{ cookiecutter.project_slug }}{% else %}{{ cookiecutter.project_slug }}{% endif %}'.commands.base import BaseCommand from '{% if cookiecutter.namespace %}{{ cookiecutter.namespace }}.{{ cookiecutter.project_slug }}{% else %}{{ cookiecutter.project_slug }}{% endif %}' import PROJECT_DIR class Configure(BaseCommand): def execute(self): os.chdir(os.path.join(PROJECT_DIR, 'build'))<|fim▁hole|><|fim▁end|>
subprocess.run(['cmake', PROJECT_DIR])
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python # coding: utf8 import os import subprocess from '{% if cookiecutter.namespace %}{{ cookiecutter.namespace }}.{{ cookiecutter.project_slug }}{% else %}{{ cookiecutter.project_slug }}{% endif %}'.commands.base import BaseCommand from '{% if cookiecutter.namespace %}{{ cookiecutter.namespace }}.{{ cookiecutter.project_slug }}{% else %}{{ cookiecutter.project_slug }}{% endif %}' import PROJECT_DIR class Configure(BaseCommand): <|fim_middle|> <|fim▁end|>
def execute(self): os.chdir(os.path.join(PROJECT_DIR, 'build')) subprocess.run(['cmake', PROJECT_DIR])
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python # coding: utf8 import os import subprocess from '{% if cookiecutter.namespace %}{{ cookiecutter.namespace }}.{{ cookiecutter.project_slug }}{% else %}{{ cookiecutter.project_slug }}{% endif %}'.commands.base import BaseCommand from '{% if cookiecutter.namespace %}{{ cookiecutter.namespace }}.{{ cookiecutter.project_slug }}{% else %}{{ cookiecutter.project_slug }}{% endif %}' import PROJECT_DIR class Configure(BaseCommand): def execute(self): <|fim_middle|> <|fim▁end|>
os.chdir(os.path.join(PROJECT_DIR, 'build')) subprocess.run(['cmake', PROJECT_DIR])
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python # coding: utf8 import os import subprocess from '{% if cookiecutter.namespace %}{{ cookiecutter.namespace }}.{{ cookiecutter.project_slug }}{% else %}{{ cookiecutter.project_slug }}{% endif %}'.commands.base import BaseCommand from '{% if cookiecutter.namespace %}{{ cookiecutter.namespace }}.{{ cookiecutter.project_slug }}{% else %}{{ cookiecutter.project_slug }}{% endif %}' import PROJECT_DIR class Configure(BaseCommand): def <|fim_middle|>(self): os.chdir(os.path.join(PROJECT_DIR, 'build')) subprocess.run(['cmake', PROJECT_DIR]) <|fim▁end|>
execute
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say<|fim▁hole|># from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2<|fim▁end|>
# def my_add (a, b): # return a + b # # Then we get import this...
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): <|fim_middle|> # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2)
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): <|fim_middle|> def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
self.function = function
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): <|fim_middle|> def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
return Infix(lambda x: self.function(other, x))
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): <|fim_middle|> def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
return self.function(other)
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): <|fim_middle|> def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
return Infix(lambda x, self=self, other=other: self.function(other, x))
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): <|fim_middle|> def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
return self.function(other)
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): <|fim_middle|> # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
return self.function(value1, value2)
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def <|fim_middle|>(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
__init__
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def <|fim_middle|>(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
__ror__
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def <|fim_middle|>(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
__or__
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def <|fim_middle|>(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
__rlshift__
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def <|fim_middle|>(self, other): return self.function(other) def __call__(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
__rshift__
<|file_name|>Infix.py<|end_file_name|><|fim▁begin|># Allows the creation of infix operators # Thanks to Ferdinand Jamitzky # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122 class Infix(object): def __init__(self, function): self.function = function def __ror__(self, other): return Infix(lambda x: self.function(other, x)) def __or__(self, other): return self.function(other) def __rlshift__(self, other): return Infix(lambda x, self=self, other=other: self.function(other, x)) def __rshift__(self, other): return self.function(other) def <|fim_middle|>(self, value1, value2): return self.function(value1, value2) # To create a binary operator just make a function that takes 2 arguments like say # def my_add (a, b): # return a + b # # Then we get import this... # from Infix import Infix # Lets us make binary infix style operators # # Then we make the operator, lets call it p... # p = Infix(my_add) # # Now to use it just put in # arg1 |p| arg2 <|fim▁end|>
__call__
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from flask import Blueprint, request, render_template from ..load import processing_results<|fim▁hole|>from ..abbr import get_abbr_map abbr_map = get_abbr_map() liner_mod = Blueprint('liner', __name__, template_folder='templates', static_folder='static') @liner_mod.route('/liner', methods=['GET', 'POST']) def liner(): if request.method == 'POST': query = request.form['liner-text'] text = query.split('.')[:-1] if len(text) == 0: return render_template('projects/line.html', message='Please separate each line with "."') abbr_expanded_text = "" for word in query.split(): if word in abbr_map: abbr_expanded_text += abbr_map[word] else: abbr_expanded_text += word abbr_expanded_text += " " data, emotion_sents, score, line_sentiment, text, length = processing_results(text) return render_template('projects/line.html', data=[data, emotion_sents, score, zip(text, line_sentiment), length, abbr_expanded_text]) else: return render_template('projects/line.html')<|fim▁end|>
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from flask import Blueprint, request, render_template from ..load import processing_results from ..abbr import get_abbr_map abbr_map = get_abbr_map() liner_mod = Blueprint('liner', __name__, template_folder='templates', static_folder='static') @liner_mod.route('/liner', methods=['GET', 'POST']) def liner(): <|fim_middle|> <|fim▁end|>
if request.method == 'POST': query = request.form['liner-text'] text = query.split('.')[:-1] if len(text) == 0: return render_template('projects/line.html', message='Please separate each line with "."') abbr_expanded_text = "" for word in query.split(): if word in abbr_map: abbr_expanded_text += abbr_map[word] else: abbr_expanded_text += word abbr_expanded_text += " " data, emotion_sents, score, line_sentiment, text, length = processing_results(text) return render_template('projects/line.html', data=[data, emotion_sents, score, zip(text, line_sentiment), length, abbr_expanded_text]) else: return render_template('projects/line.html')
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from flask import Blueprint, request, render_template from ..load import processing_results from ..abbr import get_abbr_map abbr_map = get_abbr_map() liner_mod = Blueprint('liner', __name__, template_folder='templates', static_folder='static') @liner_mod.route('/liner', methods=['GET', 'POST']) def liner(): if request.method == 'POST': <|fim_middle|> else: return render_template('projects/line.html') <|fim▁end|>
query = request.form['liner-text'] text = query.split('.')[:-1] if len(text) == 0: return render_template('projects/line.html', message='Please separate each line with "."') abbr_expanded_text = "" for word in query.split(): if word in abbr_map: abbr_expanded_text += abbr_map[word] else: abbr_expanded_text += word abbr_expanded_text += " " data, emotion_sents, score, line_sentiment, text, length = processing_results(text) return render_template('projects/line.html', data=[data, emotion_sents, score, zip(text, line_sentiment), length, abbr_expanded_text])
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from flask import Blueprint, request, render_template from ..load import processing_results from ..abbr import get_abbr_map abbr_map = get_abbr_map() liner_mod = Blueprint('liner', __name__, template_folder='templates', static_folder='static') @liner_mod.route('/liner', methods=['GET', 'POST']) def liner(): if request.method == 'POST': query = request.form['liner-text'] text = query.split('.')[:-1] if len(text) == 0: <|fim_middle|> abbr_expanded_text = "" for word in query.split(): if word in abbr_map: abbr_expanded_text += abbr_map[word] else: abbr_expanded_text += word abbr_expanded_text += " " data, emotion_sents, score, line_sentiment, text, length = processing_results(text) return render_template('projects/line.html', data=[data, emotion_sents, score, zip(text, line_sentiment), length, abbr_expanded_text]) else: return render_template('projects/line.html') <|fim▁end|>
return render_template('projects/line.html', message='Please separate each line with "."')
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from flask import Blueprint, request, render_template from ..load import processing_results from ..abbr import get_abbr_map abbr_map = get_abbr_map() liner_mod = Blueprint('liner', __name__, template_folder='templates', static_folder='static') @liner_mod.route('/liner', methods=['GET', 'POST']) def liner(): if request.method == 'POST': query = request.form['liner-text'] text = query.split('.')[:-1] if len(text) == 0: return render_template('projects/line.html', message='Please separate each line with "."') abbr_expanded_text = "" for word in query.split(): if word in abbr_map: <|fim_middle|> else: abbr_expanded_text += word abbr_expanded_text += " " data, emotion_sents, score, line_sentiment, text, length = processing_results(text) return render_template('projects/line.html', data=[data, emotion_sents, score, zip(text, line_sentiment), length, abbr_expanded_text]) else: return render_template('projects/line.html') <|fim▁end|>
abbr_expanded_text += abbr_map[word]
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from flask import Blueprint, request, render_template from ..load import processing_results from ..abbr import get_abbr_map abbr_map = get_abbr_map() liner_mod = Blueprint('liner', __name__, template_folder='templates', static_folder='static') @liner_mod.route('/liner', methods=['GET', 'POST']) def liner(): if request.method == 'POST': query = request.form['liner-text'] text = query.split('.')[:-1] if len(text) == 0: return render_template('projects/line.html', message='Please separate each line with "."') abbr_expanded_text = "" for word in query.split(): if word in abbr_map: abbr_expanded_text += abbr_map[word] else: <|fim_middle|> abbr_expanded_text += " " data, emotion_sents, score, line_sentiment, text, length = processing_results(text) return render_template('projects/line.html', data=[data, emotion_sents, score, zip(text, line_sentiment), length, abbr_expanded_text]) else: return render_template('projects/line.html') <|fim▁end|>
abbr_expanded_text += word
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from flask import Blueprint, request, render_template from ..load import processing_results from ..abbr import get_abbr_map abbr_map = get_abbr_map() liner_mod = Blueprint('liner', __name__, template_folder='templates', static_folder='static') @liner_mod.route('/liner', methods=['GET', 'POST']) def liner(): if request.method == 'POST': query = request.form['liner-text'] text = query.split('.')[:-1] if len(text) == 0: return render_template('projects/line.html', message='Please separate each line with "."') abbr_expanded_text = "" for word in query.split(): if word in abbr_map: abbr_expanded_text += abbr_map[word] else: abbr_expanded_text += word abbr_expanded_text += " " data, emotion_sents, score, line_sentiment, text, length = processing_results(text) return render_template('projects/line.html', data=[data, emotion_sents, score, zip(text, line_sentiment), length, abbr_expanded_text]) else: <|fim_middle|> <|fim▁end|>
return render_template('projects/line.html')
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from flask import Blueprint, request, render_template from ..load import processing_results from ..abbr import get_abbr_map abbr_map = get_abbr_map() liner_mod = Blueprint('liner', __name__, template_folder='templates', static_folder='static') @liner_mod.route('/liner', methods=['GET', 'POST']) def <|fim_middle|>(): if request.method == 'POST': query = request.form['liner-text'] text = query.split('.')[:-1] if len(text) == 0: return render_template('projects/line.html', message='Please separate each line with "."') abbr_expanded_text = "" for word in query.split(): if word in abbr_map: abbr_expanded_text += abbr_map[word] else: abbr_expanded_text += word abbr_expanded_text += " " data, emotion_sents, score, line_sentiment, text, length = processing_results(text) return render_template('projects/line.html', data=[data, emotion_sents, score, zip(text, line_sentiment), length, abbr_expanded_text]) else: return render_template('projects/line.html') <|fim▁end|>
liner
<|file_name|>tests.py<|end_file_name|><|fim▁begin|>import unittest from app import read_config class ConfigFileReaderTest(unittest.TestCase): def test_read(self): config = read_config('config') self.assertEqual(config['cmus_host'], 'raspberry')<|fim▁hole|> if __name__ == '__main__': unittest.main()<|fim▁end|>
self.assertEqual(config['cmus_passwd'], 'PaSsWd') self.assertEqual(config['app_host'], 'localhost') self.assertEqual(config['app_port'], '8080')
<|file_name|>tests.py<|end_file_name|><|fim▁begin|>import unittest from app import read_config class ConfigFileReaderTest(unittest.TestCase): <|fim_middle|> if __name__ == '__main__': unittest.main() <|fim▁end|>
def test_read(self): config = read_config('config') self.assertEqual(config['cmus_host'], 'raspberry') self.assertEqual(config['cmus_passwd'], 'PaSsWd') self.assertEqual(config['app_host'], 'localhost') self.assertEqual(config['app_port'], '8080')
<|file_name|>tests.py<|end_file_name|><|fim▁begin|>import unittest from app import read_config class ConfigFileReaderTest(unittest.TestCase): def test_read(self): <|fim_middle|> if __name__ == '__main__': unittest.main() <|fim▁end|>
config = read_config('config') self.assertEqual(config['cmus_host'], 'raspberry') self.assertEqual(config['cmus_passwd'], 'PaSsWd') self.assertEqual(config['app_host'], 'localhost') self.assertEqual(config['app_port'], '8080')
<|file_name|>tests.py<|end_file_name|><|fim▁begin|>import unittest from app import read_config class ConfigFileReaderTest(unittest.TestCase): def test_read(self): config = read_config('config') self.assertEqual(config['cmus_host'], 'raspberry') self.assertEqual(config['cmus_passwd'], 'PaSsWd') self.assertEqual(config['app_host'], 'localhost') self.assertEqual(config['app_port'], '8080') if __name__ == '__main__': <|fim_middle|> <|fim▁end|>
unittest.main()
<|file_name|>tests.py<|end_file_name|><|fim▁begin|>import unittest from app import read_config class ConfigFileReaderTest(unittest.TestCase): def <|fim_middle|>(self): config = read_config('config') self.assertEqual(config['cmus_host'], 'raspberry') self.assertEqual(config['cmus_passwd'], 'PaSsWd') self.assertEqual(config['app_host'], 'localhost') self.assertEqual(config['app_port'], '8080') if __name__ == '__main__': unittest.main() <|fim▁end|>
test_read
<|file_name|>runtests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import os import sys import django from django.conf import settings DEFAULT_SETTINGS = dict( INSTALLED_APPS=[ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sites", "pinax.pinax_hello", "pinax.pinax_hello.tests" ], MIDDLEWARE_CLASSES=[], DATABASES={ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:", } },<|fim▁hole|> SITE_ID=1, ROOT_URLCONF="pinax.pinax_hello.tests.urls", SECRET_KEY="notasecret", ) def runtests(*test_args): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ["pinax.pinax_hello.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures) if __name__ == "__main__": runtests(*sys.argv[1:])<|fim▁end|>
<|file_name|>runtests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import os import sys import django from django.conf import settings DEFAULT_SETTINGS = dict( INSTALLED_APPS=[ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sites", "pinax.pinax_hello", "pinax.pinax_hello.tests" ], MIDDLEWARE_CLASSES=[], DATABASES={ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:", } }, SITE_ID=1, ROOT_URLCONF="pinax.pinax_hello.tests.urls", SECRET_KEY="notasecret", ) def runtests(*test_args): <|fim_middle|> if __name__ == "__main__": runtests(*sys.argv[1:]) <|fim▁end|>
if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ["pinax.pinax_hello.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures)
<|file_name|>runtests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import os import sys import django from django.conf import settings DEFAULT_SETTINGS = dict( INSTALLED_APPS=[ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sites", "pinax.pinax_hello", "pinax.pinax_hello.tests" ], MIDDLEWARE_CLASSES=[], DATABASES={ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:", } }, SITE_ID=1, ROOT_URLCONF="pinax.pinax_hello.tests.urls", SECRET_KEY="notasecret", ) def runtests(*test_args): if not settings.configured: <|fim_middle|> django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ["pinax.pinax_hello.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures) if __name__ == "__main__": runtests(*sys.argv[1:]) <|fim▁end|>
settings.configure(**DEFAULT_SETTINGS)
<|file_name|>runtests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import os import sys import django from django.conf import settings DEFAULT_SETTINGS = dict( INSTALLED_APPS=[ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sites", "pinax.pinax_hello", "pinax.pinax_hello.tests" ], MIDDLEWARE_CLASSES=[], DATABASES={ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:", } }, SITE_ID=1, ROOT_URLCONF="pinax.pinax_hello.tests.urls", SECRET_KEY="notasecret", ) def runtests(*test_args): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ["pinax.pinax_hello.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures) if __name__ == "__main__": <|fim_middle|> <|fim▁end|>
runtests(*sys.argv[1:])
<|file_name|>runtests.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import os import sys import django from django.conf import settings DEFAULT_SETTINGS = dict( INSTALLED_APPS=[ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sites", "pinax.pinax_hello", "pinax.pinax_hello.tests" ], MIDDLEWARE_CLASSES=[], DATABASES={ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:", } }, SITE_ID=1, ROOT_URLCONF="pinax.pinax_hello.tests.urls", SECRET_KEY="notasecret", ) def <|fim_middle|>(*test_args): if not settings.configured: settings.configure(**DEFAULT_SETTINGS) django.setup() parent = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, parent) try: from django.test.runner import DiscoverRunner runner_class = DiscoverRunner test_args = ["pinax.pinax_hello.tests"] except ImportError: from django.test.simple import DjangoTestSuiteRunner runner_class = DjangoTestSuiteRunner test_args = ["tests"] failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args) sys.exit(failures) if __name__ == "__main__": runtests(*sys.argv[1:]) <|fim▁end|>
runtests
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def swLed(ev=None):<|fim▁hole|> def loop(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def destroy(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy()<|fim▁end|>
global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off")
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): <|fim_middle|> def swLed(ev=None): global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off") def loop(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def destroy(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy() <|fim▁end|>
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def swLed(ev=None): <|fim_middle|> def loop(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def destroy(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy() <|fim▁end|>
global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off")
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def swLed(ev=None): global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off") def loop(): <|fim_middle|> def destroy(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy() <|fim▁end|>
GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def swLed(ev=None): global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off") def loop(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def destroy(): <|fim_middle|> if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy() <|fim▁end|>
GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def swLed(ev=None): global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off") def loop(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def destroy(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here <|fim_middle|> <|fim▁end|>
setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy()
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def <|fim_middle|>(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def swLed(ev=None): global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off") def loop(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def destroy(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy() <|fim▁end|>
setup
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def <|fim_middle|>(ev=None): global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off") def loop(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def destroy(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy() <|fim▁end|>
swLed
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def swLed(ev=None): global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off") def <|fim_middle|>(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def destroy(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy() <|fim▁end|>
loop
<|file_name|>knock-rgb-led-smd.py<|end_file_name|><|fim▁begin|>import RPi.GPIO as GPIO KnockPin = 11 LedPin = 12 Led_status = 1 def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output GPIO.setup(KnockPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to off led def swLed(ev=None): global Led_status Led_status = not Led_status GPIO.output(LedPin, Led_status) # switch led status(on-->off; off-->on) print "LED: " + ("on" if Led_status else "off") def loop(): GPIO.add_event_detect(KnockPin, GPIO.FALLING, callback=swLed, bouncetime=200) # wait for falling while True: pass # Don't do anything def <|fim_middle|>(): GPIO.output(LedPin, GPIO.LOW) # led off GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy() <|fim▁end|>
destroy
<|file_name|>_type.py<|end_file_name|><|fim▁begin|># ---------------------------------------------------------------------------- # Copyright (c) 2016-2021, QIIME 2 development team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file LICENSE, distributed with this software. # ---------------------------------------------------------------------------- from qiime2.plugin import SemanticType from ..plugin_setup import plugin from . import AlphaDiversityDirectoryFormat SampleData = SemanticType('SampleData', field_names='type') AlphaDiversity = SemanticType('AlphaDiversity', variant_of=SampleData.field['type']) plugin.register_semantic_types(SampleData, AlphaDiversity)<|fim▁hole|> plugin.register_semantic_type_to_format( SampleData[AlphaDiversity], artifact_format=AlphaDiversityDirectoryFormat )<|fim▁end|>
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1]<|fim▁hole|> line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit()<|fim▁end|>
return None def get_python_diana_version():
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): <|fim_middle|> def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): <|fim_middle|> if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1]
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": <|fim_middle|> return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
return name_pieces[1]
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": <|fim_middle|> <|fim▁end|>
if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit()
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): <|fim_middle|> if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1)
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: <|fim_middle|> else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4]
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: <|fim_middle|> if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib"
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: <|fim_middle|> else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2]
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: <|fim_middle|> qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib"
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): <|fim_middle|> # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
os.mkdir("modules")
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): <|fim_middle|> sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: sys.exit(1) # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
os.mkdir(output_dir)
<|file_name|>configure.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python import glob, os, sys import sipconfig from PyQt4 import pyqtconfig def get_diana_version(): depends = filter(lambda line: line.startswith("Depends:"), open("debian/control").readlines()) for line in depends: pieces = line.split() for piece in pieces: name_pieces = piece.strip(",").split("-") if len(name_pieces) == 2 and name_pieces[0] == "diana": return name_pieces[1] return None def get_python_diana_version(): line = open("debian/changelog").readline() pieces = line.split() return pieces[1][1:-1] if __name__ == "__main__": if len(sys.argv) not in (1, 3, 5): sys.stderr.write("Usage: %s [<directory containing diana headers> <directory containing libdiana>] " "[<directory containing metlibs headers> <directory containing metlibs libraries>]\n" % sys.argv[0]) sys.exit(1) if len(sys.argv) == 5: metlibs_inc_dir = sys.argv[3] metlibs_lib_dir = sys.argv[4] else: metlibs_inc_dir = "/usr/include/metlibs" metlibs_lib_dir = "/usr/lib" if len(sys.argv) >= 3: diana_inc_dir = sys.argv[1] diana_lib_dir = sys.argv[2] else: diana_inc_dir = "/usr/include/diana" diana_lib_dir = "/usr/lib" qt_pkg_dir = os.getenv("qt_pkg_dir") python_diana_pkg_dir = os.getenv("python_diana_pkg_dir") dest_pkg_dir = os.path.join(python_diana_pkg_dir, "metno") config = pyqtconfig.Configuration() # The name of the SIP build file generated by SIP and used by the build # system. sip_files_dir = "sip" modules = ["std", "metlibs", "diana"] if not os.path.exists("modules"): os.mkdir("modules") # Run SIP to generate the code. output_dirs = [] for module in modules: output_dir = os.path.join("modules", module) build_file = module + ".sbf" build_path = os.path.join(output_dir, build_file) if not os.path.exists(output_dir): os.mkdir(output_dir) sip_file = os.path.join("sip", module, module+".sip") command = " ".join([config.sip_bin, "-c", output_dir, "-b", build_path, "-I"+config.sip_inc_dir, "-I"+config.pyqt_sip_dir, "-I"+diana_inc_dir, "-I/usr/include", "-I"+metlibs_inc_dir, "-I"+qt_pkg_dir+"/include", "-I"+qt_pkg_dir+"/share/sip/PyQt4", "-Isip", config.pyqt_sip_flags, "-w", "-o", # generate docstrings for signatures sip_file]) sys.stdout.write(command+"\n") sys.stdout.flush() if os.system(command) != 0: <|fim_middle|> # Create the Makefile (within the diana directory). makefile = pyqtconfig.QtGuiModuleMakefile( config, build_file, dir=output_dir, install_dir=dest_pkg_dir, qt=["QtCore", "QtGui", "QtNetwork", "QtXml", "QtXmlPatterns"] ) if module == "diana": makefile.extra_include_dirs += [ diana_inc_dir, os.path.join(diana_inc_dir, "PaintGL"), metlibs_inc_dir, qt_pkg_dir+"/include" ] makefile.extra_lib_dirs += [diana_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["diana"] if module == "metlibs": makefile.extra_include_dirs.append(diana_inc_dir) makefile.extra_include_dirs.append("/usr/include/metlibs") makefile.extra_lib_dirs += [diana_lib_dir, "/usr/lib", metlibs_lib_dir, qt_pkg_dir+"/lib"] makefile.extra_lflags += ["-Wl,-rpath="+diana_lib_dir, "-Wl,-fPIC"] makefile.extra_libs += ["miLogger", "coserver", "diana"] makefile.generate() output_dirs.append(output_dir) # Update the metno package version. diana_version = get_diana_version() python_diana_version = get_python_diana_version() if not diana_version or not python_diana_version: sys.stderr.write("Failed to find version information for Diana (%s) " "or python-diana (%s)\n" % (repr(diana_version), repr(python_diana_version))) sys.exit(1) f = open("python/metno/versions.py", "w") f.write('\ndiana_version = "%s"\npython_diana_version = "%s"\n' % ( diana_version, python_diana_version)) # Generate the top-level Makefile. python_files = glob.glob(os.path.join("python", "metno", "*.py")) sipconfig.ParentMakefile( configuration = config, subdirs = output_dirs, installs = [(python_files, dest_pkg_dir)] ).generate() sys.exit() <|fim▁end|>
sys.exit(1)