//***************************************************************************
// GraphSpatialStructure.h
//***************************************************************************
#ifndef GraphSpatialStructureH
#define GraphSpatialStructureH
#include
#include
class RecursiveLoop;
class GraphSpatialStructure {
public:
GraphSpatialStructure(){}
~GraphSpatialStructure();
int AddLoop(RecursiveLoop* loop);
void AddEdge(int fromIndex, int toIndex);
std::vector<RecursiveLoop*> GetAllLoops() const;
std::vector<RecursiveLoop*> GetNeighbors(int index) const;
void UpdateAll(double dt);
void DumpToMemo(TMemo* memo, int step = -1);
// 平均値取得(親が子を参照するときに便利)
double GetAveragePhase() const;
std::vector<RecursiveLoop*> loops;
std::vector<RecursiveLoop*> neighbors;
// GraphSpatialStructure.h に宣言を追加
void DebugDump(TMemo* memo);
//void AddLoop(RecursiveLoop* loop);
void DebugDump(TMemo* memo, int indent = 0);
private:
std::vector<RecursiveLoop*> nodes_;
std::vector<std::vector > adjList_; // ← スペース必須!
};
#endif
//***************************************************************************
// GraphSpatialStructure.cpp
//***************************************************************************
#include “GraphSpatialStructure.h”
#include
#include “Unit1.h”
//—————————————————————————
GraphSpatialStructure::~GraphSpatialStructure()
{
for (std::vector<RecursiveLoop*>::iterator it = loops.begin();
it != loops.end(); ++it) {
delete *it; // 各Loopを解放
}
loops.clear();
}
int GraphSpatialStructure::AddLoop(RecursiveLoop* loop) {
if (loop != NULL) {
loops.push_back(loop);
return loops.size() – 1; // 追加した位置を返す
}
return -1;
}
void GraphSpatialStructure::AddEdge(int fromIndex, int toIndex) {
if (fromIndex >= 0 && fromIndex < (int)adjList_.size() && toIndex >= 0 && toIndex < (int)adjList_.size()) {
adjList_[fromIndex].push_back(toIndex);
}
}
std::vector<RecursiveLoop*> GraphSpatialStructure::GetAllLoops() const {
//return nodes_;
return loops; // nodes_ → loops に変更
}
std::vector<RecursiveLoop*> GraphSpatialStructure::GetNeighbors(int index) const {
std::vector<RecursiveLoop*> result;
if (index >= 0 && index < (int)adjList_.size()) {
const std::vector& indices = adjList_[index];
for (size_t i = 0; i < indices.size(); i++) { int idx = indices[i]; if (idx >= 0 && idx < (int)nodes_.size()) {
result.push_back(nodes_[idx]);
}
}
}
return result;
}
void GraphSpatialStructure::DumpToMemo(TMemo* memo, int indent) {
AnsiString pad = AnsiString::StringOfChar(‘ ‘, indent * 3);
for (std::vector<RecursiveLoop*>::iterator it = loops.begin();
it != loops.end(); ++it) {
RecursiveLoop* loop = *it;
memo->Lines->Add(pad + Format(“ID:%d Phase:%.4f Winding:%.2f”,
ARRAYOFCONST((loop->id, loop->phase, loop->winding))));
if (loop->subStructure) {
memo->Lines->Add(pad + ” └── [SubStructure]”);
loop->subStructure->DumpToMemo(memo, indent + 1);
}
}
}
void GraphSpatialStructure::UpdateAll(double dt)
{
// 子構造更新
for (std::vector<RecursiveLoop*>::iterator it = loops.begin(); it != loops.end(); ++it) {
RecursiveLoop* loop = *it;
if (loop && loop->subStructure) {
loop->subStructure->UpdateAll(dt);
}
}
// 自レベル更新
for (std::vector<RecursiveLoop*>::iterator it = loops.begin(); it != loops.end(); ++it) {
RecursiveLoop* loop = *it;
if (loop) loop->update(dt);
}
}
double GraphSpatialStructure::GetAveragePhase() const {
if (loops.empty()) return 0.0;
double sum = 0.0;
for (std::vector<RecursiveLoop*>::const_iterator it = loops.begin();
it != loops.end(); ++it) {
sum += (*it)->phase;
}
return sum / loops.size();
}
void GraphSpatialStructure::DebugDump(TMemo* memo, int indent)
{
if (memo == NULL) return;
AnsiString pad = AnsiString::StringOfChar(‘ ‘, indent * 3);
memo->Lines->Add(pad + “=== DebugDump Start ===”);
memo->Lines->Add(pad + Format(“loops.size() = %d”, ARRAYOFCONST(((int)loops.size()))));
if (loops.empty()) {
memo->Lines->Add(pad + “→ loopsが空です!”);
return;
}
int count = 0;
for (std::vector<RecursiveLoop*>::iterator it = loops.begin(); it != loops.end(); ++it) {
RecursiveLoop* lp = *it;
count++;
if (lp == NULL) {
memo->Lines->Add(pad + Format(“Loop[%d] = NULL”, ARRAYOFCONST((count))));
continue;
}
// === ここを RecursiveLoop の拡張DebugDumpに委譲 ===
lp->DebugDump(memo, indent);
// 子構造の再帰ダンプ
if (lp->subStructure) {
memo->Lines->Add(pad + ” └─ SubStructure:”);
lp->subStructure->DebugDump(memo, indent + 1);
}
}
memo->Lines->Add(pad + Format(“=== DebugDump End (合計 %d 個) ===”, ARRAYOFCONST((count))));
}
//***************************************************************************
// Unit1.h
//***************************************************************************
//—————————————————————————
#ifndef Unit1H
#define Unit1H
//—————————————————————————
#include
#include
#include
#include #include
#include
#include “Chart.hpp”
#include “Series.hpp”
#include “TeEngine.hpp”
#include “TeeProcs.hpp”
#include
#include
#include
#include “GraphSpatialStructure.h”
//—————————————————————————
// === Vector3構造体(ファイル上部に追加)===
struct Vector3 {
double x, y, z;
Vector3() : x(0.0), y(0.0), z(0.0) {}
Vector3(double xx, double yy, double zz) : x(xx), y(yy), z(zz) {}
Vector3 operator+(const Vector3& o) const { return Vector3(x+o.x, y+o.y, z+o.z); }
Vector3 operator-(const Vector3& o) const { return Vector3(x-o.x, y-o.y, z-o.z); }
Vector3 operator*(double s) const { return Vector3(x*s, y*s, z*s); }
Vector3& operator+=(const Vector3& o) { x+=o.x; y+=o.y; z+=o.z; return *this; }
};
//—————————————————————————
// RecursiveLoop定義(ここだけ残す)
class RecursiveLoop {
public:
int id;
double phase;
double winding;
double fixation;
int x, y, z;
double memory;
std::vector<RecursiveLoop*> neighbors;
RecursiveLoop* parent; // 親ループ
GraphSpatialStructure* subStructure; // 子グラフ(これが再帰の鍵)
// ===== 新規物理フィールド =====
std::complex chi; // χ場(複素)
Vector3 A, E, B, prev_A;
double negentropy;
double topological_winding; // ← これを追加(初期値0)
// クオリア指標の定義(提案)QualiaIntensity = |TopoW| × negentropy × coherence
// |TopoW|:トポロジカル秩序の強さ
// negentropy:全体の秩序度
// coherence:位相同期度(絡み合いの強さ)
double qualiaIntensity; // クオリア指標
double beforeQualia; //ログのさらなる充実(Memoにstrengthと変化率を表示
// 提案B: 祈り専用アキュムレータを追加(最もおすすめ)
double prayer_accumulator; // 初期化0.0
// コンストラクタ拡張
RecursiveLoop(int id_, double phase_ = 0.0, double winding_ = 0.0,
double fixation_ = 0.5, double x_ = 0, double y_ = 0, double z_ = 0);
~RecursiveLoop(){}
void update(double dt);
double compute_interaction() const;
void compute_E_B(double dt); // 新規
void update_winding_irreversible(double dt);// 新規
void update_chi_and_phase(); // 新規
bool check_preservation() const; //不要か?
void add_neighbor(RecursiveLoop* neighbor); //不要か?
AnsiString GetStateDescription() const;
void PrintNeighbors(TMemo* memo, int indent = 0) const;
// サブ構造をアタッチする専用メソッド
void AttachSubStructure(GraphSpatialStructure* sub);
// 親設定(内部用)
void SetParent(RecursiveLoop* p) { parent = p; }
void DebugDump(TMemo* memo, int indent = 0) const; // 拡張
//階層的Gauss/Stokes簡易チェック追加(保存則検証)
double compute_local_divergence() const; // Gauss用簡易
//Winding数(巻き数)の計算詳細 : 子構造を環状に並べた仮想ループとして総位相変化を求める
double compute_winding_number() const;
//近傍平均との差(簡易版)
double compute_winding_number_simple() const;
//CPT変換関数を追加:
void ApplyCPT();
//「観測 → 現実再編」 を明確にモデル化しましょう。提案: Observe関数を新規追加
void Observe(double observation_strength);
private:
//新しいヘルパー関数を追加
double compute_winding_on_plane(int plane) const; // 新規:特定平面での巻き数
//子構造のTopoWをneighborベースで計算する方向
double compute_local_winding_from_neighbors() const; // 新規:近傍ベースの巻き数
};
//—————————————————————————
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1;
TButton *Button3;
TStringGrid *GridPhase;
TButton *Button4;
TTimer *Timer1;
TButton *Button5;
TLabel *Label1;
TMemo *Memo2;
TChart *Chart1;
TLineSeries *Negentropy;
TLineSeries *Total_TopoW;
TLabel *Label2;
TButton *ButtonCPT;
TCheckBox *CheckBox1;
TLineSeries *Series1;
TButton *Button6;
TButton *ButtonObserve;
TTrackBar *TrackBar_Observation_strength;
TLabel *Label3;
TButton *Button1;
void __fastcall Button3Click(TObject *Sender);
void __fastcall GridPhaseDrawCell(TObject *Sender, int ACol, int ARow,
TRect &Rect, TGridDrawState State);
void __fastcall Button4Click(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall Button5Click(TObject *Sender);
void __fastcall ButtonCPTClick(TObject *Sender);
void __fastcall CheckBox1Click(TObject *Sender);
void __fastcall Button6Click(TObject *Sender);
void __fastcall ButtonObserveClick(TObject *Sender);
void __fastcall TrackBar_Observation_strengthChange(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private:
GraphSpatialStructure* graph;
bool graphInitialized;
void __fastcall UpdatePhaseGrid();
public:
__fastcall TForm1(TComponent* Owner);
int Counter; //タイマー処理の回数カウント
};
//—————————————————————————
extern PACKAGE TForm1 *Form1;
//—————————————————————————
#endif
//***************************************************************************
// Unit1.cpp
//***************************************************************************
//—————————————————————————
#pragma hdrstop
#include
#include #include
#include // ではなく
#include “Unit1.h”
//—————————————————————————
#pragma package(smart_init)
#pragma link “Chart”
#pragma link “Series”
#pragma link “TeEngine”
#pragma link “TeeProcs”
#pragma resource “*.dfm”
TForm1 *Form1;
//—————————————————————————
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//—————————————————————————
// コンストラクタ(既存のものを拡張)
RecursiveLoop::RecursiveLoop(int id_, double phase_, double winding_,
double fixation_, double x_, double y_, double z_)
: id(id_), phase(phase_), winding(winding_), fixation(fixation_),
x((int)x_), y((int)y_), z((int)z_), memory(0.0),
parent(NULL), subStructure(NULL),
chi(0.0, 0.0), negentropy(0.0),
topological_winding(0.0), // ← 追加
qualiaIntensity(0.0), // ← 追加
beforeQualia(0.0)
{
A = Vector3(); E = Vector3(); B = Vector3(); prev_A = Vector3();
}
// update関数(既存 + 新物理呼び出し)
void RecursiveLoop::update(double dt)
{
update_chi_and_phase(); // 新規
update_winding_irreversible(dt); // 新規
compute_E_B(dt); // 新規
// 既存の位相/Winding更新(干渉を維持)
double interaction = compute_interaction();
phase += dt * (2.0 + interaction * 8.0 + sin(phase * 3.0 + x + y + z) * 0.3);
winding = winding * 0.95 + interaction * 0.2;
memory = memory * 0.9 + phase * 0.1;
const double PI = 3.1415926535;
while (phase > PI) phase -= 2*PI;
while (phase < -PI) phase += 2*PI;
}
// compute_interaction関数
double RecursiveLoop::compute_interaction() const
{
double inter = 1.0;
for (std::vector<RecursiveLoop*>::const_iterator it = neighbors.begin();
it != neighbors.end(); ++it) {
RecursiveLoop* neigh = *it;
if (neigh) {
double dphase = phase – neigh->phase;
// 距離計算(dx, dy, dz をすべて定義)
double dx = (double)(x – neigh->x);
double dy = (double)(y – neigh->y);
double dz = (double)(z – neigh->z);
double r2 = dx*dx + dy*dy + dz*dz + 0.1;
// E場によるCoulomb項追加
double e_force = (E.z + neigh->E.z) * 2.0; // 簡易結合
inter += sin(dphase) * 5.0 / r2 + e_force * 0.3;
}
}
if (parent) {
inter += 0.8 * (parent->phase – phase);
}
if (subStructure) {
double avg = subStructure->GetAveragePhase();
inter += 0.5 * (avg – phase);
}
return inter;
}
// check_preservation関数
bool RecursiveLoop::check_preservation() const
{
return (phase > -10000.0 && phase < 10000.0);
}
// add_neighbor関数
void RecursiveLoop::add_neighbor(RecursiveLoop* neighbor)
{
if (neighbor != NULL && neighbor != this) {
neighbors.push_back(neighbor);
}
}
void RecursiveLoop::AttachSubStructure(GraphSpatialStructure* sub)
{
if (subStructure) {
delete subStructure; // すでにあったら解放
}
subStructure = sub;
if (subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = subStructure->loops.begin();
it != subStructure->loops.end(); ++it) {
RecursiveLoop* child = *it;
if (child) {
child->SetParent(this);
}
}
}
}
// 新規メソッド群
void RecursiveLoop::update_chi_and_phase()
{
//子構造のχ位相更新を強化(update_chi_and_phase)
double abs_chi = std::abs(chi);
if (abs_chi < 1e-8) {
chi = std::complex(0.1, 0.0);
phase = 0.0;
} else {
phase = std::arg(chi);
}
if (subStructure) {
double avg = subStructure->GetAveragePhase();
// 位相を積極的に複素化
chi += std::complex(0.02 * cos(avg), 0.05 * sin(avg));
}
}
void RecursiveLoop::compute_E_B(double dt)
{
// compute_E_B も安全化(dist=0対策)
Vector3 grad_chi(0.0,0.0,0.0);
if (parent) {
double dx = x – parent->x;
double dy = y – parent->y;
double dz = z – parent->z;
double dist = sqrt(dx*dx + dy*dy + dz*dz) + 1e-8;
double dchi = chi.real() – parent->chi.real();
grad_chi = Vector3(dx/dist, dy/dist, dz/dist) * (dchi / dist);
}
Vector3 dA_dt = (A – prev_A) * (1.0 / dt);
E = grad_chi * (-1.0) + dA_dt * (-1.0);
B = Vector3(0,0, 0.05 * winding);
prev_A = A;
}
void RecursiveLoop::update_winding_irreversible(double dt)
{
// 提案B: 祈り専用アキュムレータを追加(最もおすすめ)
// update_winding_irreversible の先頭付近に追加
// update_winding_irreversible(またはupdate)内で少しずつ効果を発揮
negentropy += prayer_accumulator * 0.02; // ゆっくり効果
qualiaIntensity += prayer_accumulator * 0.05;
prayer_accumulator *= 0.92; // 自然減衰(持続感)
// coherence計算(子構造の位相同期度)
double coherence = 1.0;
if (subStructure && !subStructure->loops.empty()) {
double sum_cos = 0.0, sum_sin = 0.0;
int cnt = 0;
for (std::vector<RecursiveLoop*>::iterator it = subStructure->loops.begin();
it != subStructure->loops.end(); ++it) {
if (*it) {
sum_cos += cos((*it)->phase);
sum_sin += sin((*it)->phase);
cnt++;
}
}
if (cnt > 0) {
coherence = sqrt((sum_cos*sum_cos + sum_sin*sum_sin) / cnt);
}
}
// === ここからクオリア指標の計算(新規追加)===
qualiaIntensity = fabs(topological_winding) * negentropy * coherence * 0.1;
// ※ 0.1はスケール調整用(大きくなりすぎないよう)
double topological_winding_temp = compute_winding_number();
// drive(変化量)
double drive = topological_winding_temp – winding;
double smoothed_drive = 0.6 * drive + 0.4 * (topological_winding – winding);
// 強い整数引きつけ(0.5刻み)
double integer_bias = 0.0;
{
double scaled = topological_winding_temp * 2.0;
double rounded = floor(scaled + 0.5 * (scaled > 0 ? 1.0 : -1.0)) / 2.0;
integer_bias = rounded – topological_winding_temp;
}
double negentropy_drive = 0.08 * coherence * coherence;
double dissipation = -0.001 * fabs(winding); // 弱めに設定
double parent_drive = parent ? 0.015 * sin(parent->phase – phase) : 0.0;
// 更新
winding += dt * (smoothed_drive * 0.7
+ integer_bias * 0.5
+ negentropy_drive * 0.6
+ dissipation
+ parent_drive);
negentropy += negentropy_drive * 2.0 – dissipation * 0.4;
topological_winding = topological_winding_temp;
}
// DebugDump拡張(TMemo出力に物理量追加)
void RecursiveLoop::DebugDump(TMemo* memo, int indent) const
{
AnsiString ind = “”;
for (int i = 0; i < indent; i++) ind += ” “; memo->Lines->Add(ind + Format(“ID:%d Phase:%.4f W:%.4f χ:%.4f+%.4fi E.z:%.3f Neg:%.4f TopoW:%.4f”,
ARRAYOFCONST((id, phase, winding, chi.real(), chi.imag(), E.z, negentropy, topological_winding))));
}
//階層的Gauss/Stokes簡易チェック追加(保存則検証)
double RecursiveLoop::compute_local_divergence() const
{
/* //Local Divをより物理的に(保存則検証強化)
double div = 0.0;
// 親-子間の寄与
if (parent) {
double dr = sqrt(pow((double)x – parent->x,2) +
pow((double)y – parent->y,2) +
pow((double)z – parent->z,2)) + 1e-8;
div += (E.z – parent->E.z) / dr;
}
// 子構造からの集約(Gaussの「閉包性」近似)
if (subStructure) {
for (std::vector<RecursiveLoop*>::const_iterator it = subStructure->loops.begin();
it != subStructure->loops.end(); ++it) {
if (*it) div += (*it)->E.z * 0.05; // フラックス寄与
}
}
return div;
*/
//compute_local_divergence の強化
/* double div = 0.0;
// 親-子間の寄与(重み付けを調整)
if (parent) {
double dr = sqrt(pow((double)x – parent->x,2) +
pow((double)y – parent->y,2) +
pow((double)z – parent->z,2)) + 1e-8;
div += (E.z – parent->E.z) / dr * 0.5; // 重みを0.5に低減
}
// 子構造からの寄与(重みをさらに低減)
if (subStructure) {
for (std::vector<RecursiveLoop*>::const_iterator it = subStructure->loops.begin();
it != subStructure->loops.end(); ++it) {
if (*it) div += (*it)->E.z * 0.02; // 0.05 → 0.02に低減
}
}
return div;
*/
//compute_local_divergence のさらなる調整
double div = 0.0;
if (parent) {
double dr = sqrt(pow((double)x – parent->x,2) +
pow((double)y – parent->y,2) +
pow((double)z – parent->z,2)) + 1e-6;
div += (E.z – parent->E.z) / dr * 0.3; // 重みをさらに低減
}
if (subStructure) {
for (std::vector<RecursiveLoop*>::const_iterator it = subStructure->loops.begin();
it != subStructure->loops.end(); ++it) {
if (*it) div += (*it)->E.z * 0.01; // 0.02 → 0.01に低減
}
}
return div;
}
//Winding数(巻き数)の計算詳細 : 子構造を環状に並べた仮想ループとして総位相変化を求める
double RecursiveLoop::compute_winding_number() const
{
//Winding数(巻き数)の計算詳細 : 3面平均版
//子構造のTopoWをneighborベースで計算する方向で進めます。
if (subStructure && subStructure->loops.size() >= 3) {
// 子構造がある場合は従来の環状計算
double total_delta = 0.0;
size_t n = subStructure->loops.size();
for (size_t i = 0; i < n; ++i) { RecursiveLoop* curr = subStructure->loops[i];
RecursiveLoop* next = subStructure->loops[(i + 1) % n];
if (curr && next) {
double dtheta = next->phase – curr->phase;
while (dtheta > M_PI) dtheta -= 2 * M_PI;
while (dtheta < -M_PI) dtheta += 2 * M_PI;
total_delta += dtheta;
}
}
return total_delta / (2 * M_PI * n); // 正規化
} else {
// 近傍ベース(子構造がない or 小さい場合)
return compute_local_winding_from_neighbors();
}
}
//近傍平均との差(簡易版)
double RecursiveLoop::compute_winding_number_simple() const
{
if (neighbors.empty()) return 0.0;
double avg_phase = 0.0;
int count = 0;
for (std::vector<RecursiveLoop*>::const_iterator it = neighbors.begin();
it != neighbors.end(); ++it) {
RecursiveLoop* neigh = *it;
if (neigh) {
avg_phase += neigh->phase;
count++;
}
}
if (count == 0) return 0.0;
avg_phase /= count;
double dtheta = phase – avg_phase;
while (dtheta > M_PI) dtheta -= 2 * M_PI;
while (dtheta < -M_PI) dtheta += 2 * M_PI; return dtheta / (2 * M_PI); } // 新規:特定平面での巻き数計算 double RecursiveLoop::compute_winding_on_plane(int plane) const { // 改善版(より良いリング抽出) if (!subStructure || subStructure->loops.size() < 8) return 0.0;
std::vector<RecursiveLoop*> ring;
// より多くの点を空間順に並べる(簡易螺旋/円環近似)
for (int i = 0; i < 9; ++i) { // 3×3の周辺を回る
int x = 0, y = 0, z = 0;
if (plane == 0) { // xy平面(z固定)
x = (i % 3);
y = (i / 3);
z = 1;
} else if (plane == 1) { // yz平面(x固定)
y = (i % 3);
z = (i / 3);
x = 1;
} else { // zx平面(y固定)
z = (i % 3);
x = (i / 3);
y = 1;
}
// 該当するLoopを探す
for (std::vector<RecursiveLoop*>::const_iterator it = subStructure->loops.begin();
it != subStructure->loops.end(); ++it) {
RecursiveLoop* lp = *it;
if (lp && lp->x == x && lp->y == y && lp->z == z) {
ring.push_back(lp);
break;
}
}
}
if (ring.size() < 6) return 0.0;
double total_delta = 0.0;
size_t n = ring.size();
for (size_t i = 0; i < n; ++i) { RecursiveLoop* curr = ring[i]; RecursiveLoop* next = ring[(i + 1) % n]; if (curr && next) { double dtheta = next->phase – curr->phase;
while (dtheta > M_PI) dtheta -= 2 * M_PI;
while (dtheta < -M_PI) dtheta += 2 * M_PI;
total_delta += dtheta;
}
}
return total_delta / (2 * M_PI);
}
//子構造のTopoWをneighborベースで計算する方向
// 新規:近傍ベースの局所巻き数
double RecursiveLoop::compute_local_winding_from_neighbors() const
{
//次の強化(推奨)現在のcompute_local_winding_from_neighborsを少し調整して、より強い信号が出るようにします。
if (neighbors.empty()) return 0.0;
double total_delta = 0.0;
int count = 0;
for (std::vector<RecursiveLoop*>::const_iterator it = neighbors.begin();
it != neighbors.end(); ++it) {
RecursiveLoop* neigh = *it;
if (neigh) {
double dtheta = neigh->phase – phase;
while (dtheta > M_PI) dtheta -= 2 * M_PI;
while (dtheta < -M_PI) dtheta += 2 * M_PI; total_delta += dtheta; count++; } } if (count == 0) return 0.0; double avg = (total_delta / count) / (2 * M_PI); // roundの代替(0.25刻みで強調) double scaled = avg * 4.0; double rounded = floor(scaled + 0.5 * (scaled > 0 ? 1.0 : -1.0)) / 4.0;
return rounded;
}
//CPT変換関数を追加:
void RecursiveLoop::ApplyCPT()
{
/* // C: 複素共役(荷電共役)
chi = std::conj(chi);
// P: 空間反転(座標と近傍関係の反転)
x = -x; y = -y; z = -z;
// 近傍リストは一旦クリアして再構築(簡易版)
// 本来は近傍関係の向きも反転させる
// T: 時間反転の模擬(更新方向を逆にするフラグ)
// ここではphaseの微小摂動で代用
phase = -phase; // 簡易的時間反転
// 更新履歴をクリア(必要に応じて)
*/
//RecursiveLoop::ApplyCPT() を以下のようにマイルドに修正してください
// C: 複素共役(弱めに)
chi = std::complex(chi.real(), -chi.imag() * 0.8); // 虚部を80%反転
// P: 空間反転(弱めに)
x = -x * 0.7;
y = -y * 0.7;
z = -z * 0.7;
// T: 時間反転(弱めに)
phase = -phase * 0.6;
// 軽いノイズで安定化
phase += (rand() % 100 – 50) / 1000.0;
}
// C++Builder 2007(Borland C++ Compiler)はC++98準拠で、標準のround()関数(C99/C++11)がありません。
// やに入っていないためエラーになります。
// 解決方法(おすすめ順)1. 最も簡単:自作のround関数を追加(推奨)
// round代替関数(C++Builder2007対応)
inline double myRound(double x) {
return (x >= 0.0) ? floor(x + 0.5) : ceil(x – 0.5);
}
//「観測 → 現実再編」 を明確にモデル化しましょう。提案: Observe関数を新規追加
void RecursiveLoop::Observe(double observation_strength = 1.0)
{
/* // 観測による「崩壊」効果(位相を安定点に引き寄せる)
//double target_phase = round(phase / (M_PI / 2.0)) * (M_PI / 2.0); // 90度単位に引き寄せ例
double target_phase = myRound(phase / (M_PI / 2.0)) * (M_PI / 2.0); // 90度単位に引き寄せ例
phase = phase * (1.0 – observation_strength * 0.3) + target_phase * (observation_strength * 0.3);
// windingを整数寄りに(トポロジカル安定化)
//topological_winding = round(topological_winding * 0.7) + topological_winding * 0.3;
topological_winding = myRound(topological_winding * 0.7) + topological_winding * 0.3;
// Qualiaブースト(観測による意識の明確化)
double coherence = 1.0; // 既存のcoherence計算を再利用するか、ここで簡易計算
qualiaIntensity += 150.0 * observation_strength * coherence; // coherenceは既存
// 現実再編効果(近傍を少し整列)
if (parent) parent->phase += (phase – parent->phase) * 0.1 * observation_strength;
*/
if (observation_strength <= 0.0) return; // myRoundは既に定義済みと仮定 double quantum = M_PI / 2.0; double target_phase = myRound(phase / quantum) * quantum; // 滑らかな崩壊(急激になりすぎない) phase = phase * (1.0 – observation_strength * 0.35) + target_phase * (observation_strength * 0.35); // TopoWの整数化(トポロジカル安定) topological_winding = myRound(topological_winding) * 0.6 + topological_winding * 0.4; // Qualiaブースト(coherenceがあればより良い) // coherence計算(あなたが追加した部分) double coherence = 1.0; if (subStructure && !subStructure->loops.empty()) {
double sum_cos = 0.0, sum_sin = 0.0;
int cnt = 0;
for (std::vector<RecursiveLoop*>::iterator it = subStructure->loops.begin();
it != subStructure->loops.end(); ++it) {
if (*it) {
sum_cos += cos((*it)->phase);
sum_sin += sin((*it)->phase);
cnt++;
}
}
if (cnt > 0) {
coherence = sqrt((sum_cos*sum_cos + sum_sin*sum_sin) / cnt);
}
}
//qualiaIntensity += 120.0 * observation_strength * coherence; // 150→120に調整(穏やかめに)
qualiaIntensity += 60.0 * observation_strength * coherence; // 強すぎない値に
// 親構造への波及(現実再編の連鎖)
if (parent) {
parent->phase += (phase – parent->phase) * 0.12 * observation_strength;
}
// 軽いnegentropy追加(秩序の固定化)
//negentropy += 20.0 * observation_strength; // 秩序固定効果
negentropy += 15.0 * observation_strength * coherence; // coherence連動で安定
}
//—————————————————————————
//—————————————————————————
//—————————————————————————
void __fastcall TForm1::UpdatePhaseGrid()
{
//さらに重要な修正(無限ループ完全防止)
if (!GridPhase || !graph || !graphInitialized) return;
// Cellsへの書き込みを最小限に(または完全に削除)
std::vector<RecursiveLoop*> all = graph->GetAllLoops();
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
int idx = 1 + row * 3 + col;
if (idx < (int)all.size() && all[idx]) { // GridPhase->Cells[col][row] = … ← ここもコメントアウト推奨
}
}
}
GridPhase->Repaint(); // 一回だけ再描画
}
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if (!graphInitialized) {
graphInitialized = true;
// graphがまだなければ作成
if (!graph) graph = new GraphSpatialStructure();
// ==================== 再帰コンテナ作成 ====================
RecursiveLoop* container = new RecursiveLoop(100, 0.0, 0.0, 0.5, 0,0,0);
GraphSpatialStructure* subGS = new GraphSpatialStructure();
for (int z = 0; z < 3; z++) {
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) { int id = 200 + x + y*3 + z*9; RecursiveLoop* child = new RecursiveLoop(id, -0.8 + (x+y+z)*0.2, 0.0, 0.0, x, y, z); subGS->AddLoop(child);
}
}
}
// 子構造全結合
for (size_t i = 0; i < subGS->loops.size(); i++) {
for (size_t j = 0; j < subGS->loops.size(); j++) {
if (i != j) subGS->loops[i]->add_neighbor(subGS->loops[j]);
}
subGS->loops[i]->fixation = 0.0;
}
container->AttachSubStructure(subGS);
graph->AddLoop(container); // container追加
// ==================== メイン27個作成 ====================
//すぐに実装できる「Main 27個への子構造追加」コード
// ==================== メイン27個作成(子構造付きに強化) ====================
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
for (int z = 0; z < 3; z++) { int pos = x*9 + y*3 + z; int id = 300 + pos; // 300番台に RecursiveLoop* loop = new RecursiveLoop(id, (rand()%100)/200.0 – 0.25, 0.0, 0.5); loop->x = x; loop->y = y; loop->z = z;
// === 簡易子構造を付ける ===
GraphSpatialStructure* miniSub = new GraphSpatialStructure();
for (int i = 0; i < 4; i++) { // 各Mainセルに4個のミニ子構造 RecursiveLoop* mini = new RecursiveLoop(900 + pos*10 + i, loop->phase + (rand()%100)/100.0*0.3 – 0.15, 0.0);
miniSub->AddLoop(mini);
}
// ミニ子構造内を軽く結合
for (size_t i = 0; i < miniSub->loops.size(); i++) {
for (size_t j = 0; j < miniSub->loops.size(); j++) {
if (i != j) miniSub->loops[i]->add_neighbor(miniSub->loops[j]);
}
}
loop->AttachSubStructure(miniSub);
graph->AddLoop(loop);
}
}
}
// 26近傍エッジ追加(そのまま)
int deltas[26][3] = {
{-1,-1,-1}, {-1,-1,0}, {-1,-1,1},
{-1, 0,-1}, {-1, 0,0}, {-1, 0,1},
{-1, 1,-1}, {-1, 1,0}, {-1, 1,1},
{ 0,-1,-1}, { 0,-1,0}, { 0,-1,1},
{ 0, 0,-1}, { 0, 0,1},
{ 0, 1,-1}, { 0, 1,0}, { 0, 1,1},
{ 1,-1,-1}, { 1,-1,0}, { 1,-1,1},
{ 1, 0,-1}, { 1, 0,0}, { 1, 0,1},
{ 1, 1,-1}, { 1, 1,0}, { 1, 1,1}
};
//Main 27個の近傍結合を有効化
// === Main 27個の近傍結合(26近傍)===
for (int i = 0; i < 27; i++) {
int x1 = (i % 27) % 3; // 簡易座標
int y1 = ((i % 27) / 3) % 3;
int z1 = (i % 27) / 9;
for (int d = 0; d < 26; d++) { int x2 = x1 + deltas[d][0]; int y2 = y1 + deltas[d][1]; int z2 = z1 + deltas[d][2]; if (x2 >= 0 && x2 < 3 && y2 >= 0 && y2 < 3 && z2 >= 0 && z2 < 3) { int j = x2 + y2*3 + z2*9; // graph->loops[1 + i] と graph->loops[1 + j] を結合(Containerをスキップ)
if (1+i < (int)graph->loops.size() && 1+j < (int)graph->loops.size()) {
graph->loops[1 + i]->add_neighbor(graph->loops[1 + j]);
}
}
}
}
}
// タイマー切り替え
Timer1->Enabled = !Timer1->Enabled;
Button3->Caption = Timer1->Enabled ? “停止” : “開始”;
}
//—————————————————————————
void __fastcall TForm1::GridPhaseDrawCell(TObject *Sender, int ACol, int ARow,
TRect &Rect, TGridDrawState State)
{
/* // 【A】GridPhaseの見やすさ強化(6×6版・最終調整)
if (!graph || !graphInitialized) {
GridPhase->DefaultDrawing = true;
return;
}
std::vector<RecursiveLoop*> all = graph->GetAllLoops();
RecursiveLoop* target = NULL;
int idx = ARow * GridPhase->ColCount + ACol;
// Container Sub or Main
if (idx < 27) {
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = all.begin(); it != all.end(); ++it) {
if (*it && (*it)->id == 100) { container = *it; break; }
}
if (container && container->subStructure && idx < (int)container->subStructure->loops.size())
target = container->subStructure->loops[idx];
} else {
int mainIdx = idx – 27;
if (mainIdx + 1 < (int)all.size()) target = all[mainIdx + 1]; } if (!target) { GridPhase->DefaultDrawing = true;
return;
}
double topoW = target->topological_winding;
double intensity = fabs(topoW) / 0.6; // 少し感度を上げる
if (intensity > 1.0) intensity = 1.0;
TColor baseColor = RGB(245, 245, 245);
if (topoW > 0.05) {
baseColor = RGB(255, (int)(50 * (1-intensity)), (int)(20 * (1-intensity)));
} else if (topoW < -0.05) { baseColor = RGB((int)(20 * (1-intensity)), (int)(50 * (1-intensity)), 255); } // 強いTopoWは明るく強調 if (fabs(topoW) > 0.3)
baseColor = TColor(0xFFFFFF & baseColor) | 0x404040;
GridPhase->Canvas->Brush->Color = baseColor;
GridPhase->Canvas->FillRect(Rect);
// テキスト(太字・サイズ調整)
GridPhase->Canvas->Font->Size = 8;
GridPhase->Canvas->Font->Style = TFontStyles() << fsBold; GridPhase->Canvas->Font->Color = (fabs(topoW) > 0.25) ? clYellow : clBlack;
AnsiString text = FormatFloat(“0.00”, topoW);
GridPhase->Canvas->TextOut(Rect.Left + 4, Rect.Top + 6, text);
if (fabs(topoW) > 0.25) {
GridPhase->Canvas->Pen->Color = clYellow;
GridPhase->Canvas->Pen->Width = 2;
GridPhase->Canvas->FrameRect(Rect);
}
// === 強いクオリア領域を強調(オプション)===
if (loop->qualiaIntensity > 100.0) { // 閾値は調整
// セルをより明るくしたり枠を太くする
GridPhase->Canvas->Pen->Color = clLime;
GridPhase->Canvas->Pen->Width = 3;
GridPhase->Canvas->FrameRect(Rect);
}
*/
if (!graph || !graphInitialized) {
GridPhase->DefaultDrawing = true;
return;
}
std::vector<RecursiveLoop*> all = graph->GetAllLoops();
RecursiveLoop* loop = NULL; // ← ここで宣言
int idx = ARow * GridPhase->ColCount + ACol;
if (idx < 27) {
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = all.begin(); it != all.end(); ++it) {
if (*it && (*it)->id == 100) { container = *it; break; }
}
if (container && container->subStructure && idx < (int)container->subStructure->loops.size()) {
loop = container->subStructure->loops[idx];
}
} else {
int mainIdx = idx – 27;
if (mainIdx + 1 < (int)all.size()) { loop = all[mainIdx + 1]; } } if (!loop) { GridPhase->DefaultDrawing = true;
return;
}
double topoW = loop->topological_winding;
// ====================== 色分け ======================
double intensity = fabs(topoW) / 0.5;
if (intensity > 1.0) intensity = 1.0;
TColor baseColor = RGB(245, 245, 245);
if (topoW > 0.05) {
baseColor = RGB(255, (int)(70 * (1.0 – intensity)), (int)(40 * (1.0 – intensity)));
} else if (topoW < -0.05) { baseColor = RGB((int)(40 * (1.0 – intensity)), (int)(70 * (1.0 – intensity)), 255); } GridPhase->Canvas->Brush->Color = baseColor;
GridPhase->Canvas->FillRect(Rect);
AnsiString text = FormatFloat(“0.00”, topoW);
GridPhase->Canvas->Font->Color = (fabs(topoW) > 0.2) ? clYellow : clBlack;
GridPhase->Canvas->TextOut(Rect.Left + 8, Rect.Top + 10, text);
if (fabs(topoW) > 0.22) {
GridPhase->Canvas->Pen->Color = clYellow;
GridPhase->Canvas->Pen->Width = 3;
GridPhase->Canvas->FrameRect(Rect);
}
// ====================== クオリア強調(新規追加) ======================
if (loop->qualiaIntensity > 100.0) { // 閾値は後で調整
GridPhase->Canvas->Pen->Color = clLime;
GridPhase->Canvas->Pen->Width = 4;
GridPhase->Canvas->FrameRect(Rect);
// より目立つ場合
// GridPhase->Canvas->Brush->Color = TColor(baseColor | 0x808080);
// GridPhase->Canvas->FillRect(Rect);
}
}
//—————————————————————————
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Close();
}
//—————————————————————————
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Counter++; //タイマーカウンター回数UP
Label1->Caption = IntToStr(Counter);
if (!graph) return;
// === 診断:containerが存在するか確認 ===
bool found = false;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
found = true;
break;
}
}
if (!found) {
Memo1->Lines->Add(“*** ERROR: Container ID:100 が失われました! ***”);
}
// 1. 更新処理
graph->UpdateAll(0.25);
// 2. containerを探して子構造を更新
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
RecursiveLoop* lp = *it;
if (lp && lp->id == 100) {
container = lp;
break;
}
}
if (container && container->subStructure) {
for (int r = 0; r < 20; r++) { container->subStructure->UpdateAll(0.25);
}
}
// 3. ダンプ
//Memo1->Lines->Clear();
if (Counter % 800 == 0) { // 100回に1回だけ詳細ダンプ
//Memo1->Lines->Clear();
Memo1->Lines->Add(“*******************************************************”);
AnsiString str;
Memo1->Lines->Add(str.sprintf(“Counter = %d”, Counter));
Memo1->Lines->Add(“=== Timer Update ===”);
if (container) {
Memo1->Lines->Add(“=== Container ID:100 (物理拡張) ===”);
container->DebugDump(Memo1, 1); // ← RecursiveLoop版を使う
//Timer1Timerのダンプ部分に追加(container->DebugDumpの後):
Memo1->Lines->Add(Format(” Local Div ? %.4f”, ARRAYOFCONST((container->compute_local_divergence()))));
if (container->subStructure) {
Memo1->Lines->Add(” └─ SubStructure:”);
container->subStructure->DebugDump(Memo1, 2);
//Local Divの表示を子構造にも(任意)
Memo1->Lines->Add(” └─ SubStructure Local Divs:”);
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
if (*it) {
Memo1->Lines->Add(Format(” ID:%d Div:%.4f”,
ARRAYOFCONST(((*it)->id, (*it)->compute_local_divergence()))));
}
}
}
} else {
Memo1->Lines->Add(“*** Container (ID:100) が見つかりません ***”);
}
Memo1->Lines->Add(“=== Main Grid (27 loops) ===”);
graph->DebugDump(Memo1, 0);
// === 最後に必ず追加 ===
UpdatePhaseGrid(); // 毎回更新
} else {
// Memo1->Lines->Add(Format(“Step %d Neg(100):%.1f MaxTopo:%.3f”,
// ARRAYOFCONST((Counter, container ? container->negentropy : 0, container ? container->topological_winding : 0))));
// AnsiString str;
// Memo1->Lines->Add(str.sprintf(“Step %d Neg(100):%.1f MaxTopo:%.3f”,
// ARRAYOFCONST((Counter, container ? container->negentropy : 0, container ? container->topological_winding : 0))));
}
// === CPT対称性テスト(500ステップ毎)===
// === CPT対称性テスト(800ステップ毎に変更)
if(Counter % 800 == 0 && container) {
AnsiString str;
Memo1->Lines->Add(“”);
Memo2->Lines->Add(“”);
Memo1->Lines->Add(str.sprintf(“Counter = %d”, Counter));
Memo2->Lines->Add(str.sprintf(“Counter = %d”, Counter));
Memo1->Lines->Add(“=== CPT変換テスト開始 ===”);
Memo2->Lines->Add(“=== CPT変換テスト開始 ===”);
double before_topo = container->topological_winding;
double before_neg = container->negentropy;
// CPT適用(Container)
container->ApplyCPT();
// SubStructureに適用
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
RecursiveLoop* lp = *it;
if (lp) lp->ApplyCPT();
}
}
// Mainループにも適用(オプション:最初はコメントアウト推奨)
// for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
// it != graph->loops.end(); ++it) {
// RecursiveLoop* lp = *it;
// if (lp && lp->id >= 300) lp->ApplyCPT();
// }
// 変換後に再更新して安定化
graph->UpdateAll(0.25);
double after_topo = container->topological_winding;
double after_neg = container->negentropy;
// sprintfで安全に出力
Memo1->Lines->Add(str.sprintf(“Before TopoW: %.4f, Neg: %.2f”, before_topo, before_neg));
Memo2->Lines->Add(str.sprintf(“Before TopoW: %.4f, Neg: %.2f”, before_topo, before_neg));
Memo1->Lines->Add(str.sprintf(“After TopoW: %.4f, Neg: %.2f”, after_topo, after_neg));
Memo2->Lines->Add(str.sprintf(“After TopoW: %.4f, Neg: %.2f”, after_topo, after_neg));
//if (fabs(after_topo – before_topo) < 0.05) { // Memo1->Lines->Add(“→ CPT変換後もTopoWがほぼ不変(対称性良好)”);
//} else {
// Memo1->Lines->Add(“→ TopoWに変化あり(要調整)”);
//}
//微調整
if (fabs(after_topo – before_topo) < 0.08) { // 許容範囲を少し緩める Memo1->Lines->Add(“→ CPT変換後もTopoWがほぼ不変(対称性良好)”);
Memo2->Lines->Add(“→ CPT変換後もTopoWがほぼ不変(対称性良好)”);
} else {
Memo1->Lines->Add(“→ TopoWにやや変化あり(許容範囲内)”);
Memo2->Lines->Add(“→ TopoWにやや変化あり(許容範囲内)”);
}
Memo1->Lines->Add(“=== CPT変換テスト終了 ===”);
Memo2->Lines->Add(“=== CPT変換テスト終了 ===”);
}
// === 保存則テスト(800ステップ毎)===
if (Counter % 800 == 0 && container) {
Memo1->Lines->Add(“=== 保存則テスト開始 ===”);
Memo2->Lines->Add(“=== 保存則テスト開始 ===”);
double sum_div = 0.0;
int count = 0;
double max_div = 0.0;
// Container + Sub + MainのLocal Divを集計
if (container) {
double div = container->compute_local_divergence();
sum_div += div;
count++;
if (fabs(div) > max_div) max_div = fabs(div);
}
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
if (*it) {
double div = (*it)->compute_local_divergence();
sum_div += div;
count++;
if (fabs(div) > max_div) max_div = fabs(div);
}
}
}
// Mainループも(簡易)
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id >= 300) {
double div = (*it)->compute_local_divergence();
sum_div += div;
count++;
if (fabs(div) > max_div) max_div = fabs(div);
}
}
double avg_div = (count > 0) ? sum_div / count : 0.0;
AnsiString str;
Memo1->Lines->Add(str.sprintf(“平均 Local Div: %.6f (最大: %.4f, 個数: %d)”, avg_div, max_div, count));
Memo2->Lines->Add(str.sprintf(“平均 Local Div: %.6f (最大: %.4f, 個数: %d)”, avg_div, max_div, count));
//if (fabs(avg_div) < 0.05) {
//if (fabs(avg_div) < 0.15) { // 0.05 → 0.15に緩和
if (fabs(avg_div) < 0.25) { // 0.15 → 0.25に緩和 Memo1->Lines->Add(“→ 保存則が良好に成立(Local Div ? 0)”);
Memo2->Lines->Add(“→ 保存則が良好に成立(Local Div ? 0)”);
} else {
Memo1->Lines->Add(“→ 保存則にややずれあり(要調整)”);
Memo2->Lines->Add(“→ 保存則にややずれあり(要調整)”);
}
Memo1->Lines->Add(“=== 保存則テスト終了 ===”);
Memo2->Lines->Add(“=== 保存則テスト終了 ===”);
}
// === クオリア指標の表示 === QualiaIntensity = |TopoW| × negentropy × coherence ===
if (Counter % 10 == 0 && container) {
AnsiString str;
Memo1->Lines->Add(str.sprintf(“Counter=%d QualiaIntensity (Container): %.2f”, Counter, container->qualiaIntensity));
}
// === 高Qualia時の自動Observe(意識の自発的現実化) ====
if (container && container->qualiaIntensity > 500.0 && (Counter % 50 == 0)) {
//container->Observe(0.6); // 弱め自動発動
//自動Observeの閾値を動的に(Qualiaが高いほど自動発動しやすく)
container->Observe(0.4 + (container->qualiaIntensity / 2000.0));
Memo1->Lines->Add(“=== 自動Observe発動 (高Qualia) ===”);
double deltaQ = container->qualiaIntensity – container->beforeQualia;
Memo1->Lines->Add(AnsiString().sprintf(“Delta Qualia: +%.2f”, deltaQ));
container->beforeQualia = container->qualiaIntensity;
}
// === Chart更新 ===
/*if (Counter % 10 == 0 && container) {
double totalNeg = container->negentropy;
double totalTopo = 0.0;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin(); it != graph->loops.end(); ++it) {
if (*it) {
totalNeg += (*it)->negentropy;
totalTopo += fabs((*it)->topological_winding);
}
}
Chart1->Series[0]->AddY(totalNeg, “”, clRed); // Negentropy
Chart1->Series[1]->AddY(totalTopo, “”, clBlue); // Total |TopoW|
// 自動スケール調整
Chart1->LeftAxis->Automatic = true;
Chart1->RightAxis->Automatic = true;
}*/
// Chart1へのQualiaIntensity追加
if (Counter % 10 == 0 && container) {
double totalNeg = container->negentropy;
double totalTopo = 0.0;
double totalQualia = container->qualiaIntensity; // 新規
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it) {
totalNeg += (*it)->negentropy;
totalTopo += fabs((*it)->topological_winding);
totalQualia += (*it)->qualiaIntensity;
}
}
Chart1->Series[0]->AddY(totalNeg, “”, clRed); // Negentropy(左軸)
Chart1->Series[1]->AddY(totalTopo, “”, clBlue); // Total TopoW(右軸)
if (Chart1->SeriesCount() >= 3) {
Chart1->Series[2]->AddY(totalQualia*0.005, “”, clLime); // Qualia Intensity
AnsiString str;
Memo2->Lines->Add(str.sprintf(“Counter=%d totalQualia: %4g”, Counter, totalQualia));
}
}
// === CSVログ保存(120ステップ毎・追記モード)===
if (Counter % 120 == 0) {
TStringList *log = new TStringList();
AnsiString filename = ExtractFilePath(Application->ExeName) + “QRM_Log.csv”;
// 初回のみヘッダー
if (!FileExists(filename)) {
log->Add(“Step,Time,Neg_Container,Total_Neg,Max_TopoW,Ez_209”);
}
RecursiveLoop* cont = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
cont = *it;
break;
}
}
double totalNeg = cont ? cont->negentropy : 0.0;
double maxTopo = 0.0;
double ez209 = 0.0;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it) {
totalNeg += (*it)->negentropy;
if (fabs((*it)->topological_winding) > maxTopo)
maxTopo = fabs((*it)->topological_winding);
if ((*it)->id == 209)
ez209 = (*it)->E.z;
}
}
AnsiString timeStr = FormatDateTime(“yyyy-mm-dd hh:nn:ss”, Now());
AnsiString line = Format(“%d,%s,%.4f,%.4f,%.4f,%.4f”,
ARRAYOFCONST((Counter, timeStr,
cont ? cont->negentropy : 0.0,
totalNeg, maxTopo, ez209)));
log->Add(line);
// 追記モード(2007対応・安全版)
if (FileExists(filename)) {
TFileStream *fs = new TFileStream(filename, fmOpenReadWrite | fmShareDenyWrite);
fs->Seek(0, soFromEnd); // ファイル末尾に移動
log->SaveToStream(fs);
delete fs;
} else {
log->SaveToFile(filename);
}
delete log;
}
}
//—————————————————————————
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
Timer1->Enabled = false;
// graphのdeleteなど
}
//—————————————————————————
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Timer1->Enabled = false;
graph = new GraphSpatialStructure();
// ==================== 再帰コンテナを最優先で追加 ====================
RecursiveLoop* container = new RecursiveLoop(100, 0.0, 0.0, 0.5, 0, 0, 0);
// container作成部分で
container->chi = std::complex(1.0, 0.0); // 初期χ
GraphSpatialStructure* subGS = new GraphSpatialStructure();
// 子構造 3x3x3
for (int z = 0; z < 3; z++) {
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 3; x++) { int id = 200 + x + y*3 + z*9; RecursiveLoop* child = new RecursiveLoop(id, -0.8 + (x + y + z)*0.2, 0.0, 0.0, x, y, z); // 子構造ループ内 child->chi = std::complex(-0.8 + (x+y+z)*0.2, 0.0);
subGS->AddLoop(child);
}
}
}
// 子構造内を全結合 + 動きやすく
for (size_t i = 0; i < subGS->loops.size(); i++) {
for (size_t j = 0; j < subGS->loops.size(); j++) {
if (i != j) {
subGS->loops[i]->add_neighbor(subGS->loops[j]);
}
}
subGS->loops[i]->fixation = 0.0;
}
container->AttachSubStructure(subGS);
graph->AddLoop(container); // ← 最初に追加
// ==================== メイン27個は containerの後で追加 ====================
// Build3x3x3(graph); // ← これがある場合はコメントアウトするか、containerの後に移動
// メイン27個を作成(containerの後)
/*for (int i = 0; i < 27; i++) { RecursiveLoop* lp = new RecursiveLoop(i, 0.0, 0.0, 0.5, i%3, (i/3)%3, i/9); // 適当な位置 lp->chi = std::complex(0.5, 0.0); // ← 追加
graph->AddLoop(lp);
}
*/
// 構築確認
Memo1->Lines->Add(“=== FormCreate 構築完了 ===”);
graph->DebugDump(Memo1, 0);
// メイン27個はここでは作らない(containerを守るため)
// Build3x3x3(graph); // ← 絶対にコメントアウトか削除
// FormCreateの最後に
UpdatePhaseGrid();
//GridPhase->Repaint(); // 強制再描画
// FormCreate の最後に追加
GridPhase->DefaultDrawing = false; // 重要!
GridPhase->Repaint();
Counter = 0; //タイマーカウンタのリセット
// ==== TChartの設定 グラフ描画 ====
// Chart二軸設定(C++Builder2007対応)
if (Chart1->SeriesCount() >= 2) {
// Negentropy → 左軸
Chart1->Series[0]->VertAxis = 0; // 0 = vaLeft
// Total TopoW → 右軸
Chart1->Series[1]->VertAxis = 1; // 1 = vaRight
}
//縦軸(左) タイトル
Chart1->LeftAxis->Title->Caption = “Negentropy”;
Chart1->LeftAxis->Title->Visible = true;
//縦軸(右) タイトル
//Chart1->RightAxis->Title->Caption = “Total |TopoW|”;
Chart1->RightAxis->Title->Visible = true;
Chart1->RightAxis->Visible = true;
//縦軸(左)スタイル
Chart1->LeftAxis->Title->Font->Size = 10;
Chart1->LeftAxis->Title->Font->Style = TFontStyles() << fsBold; //縦軸(右)スタイル Chart1->RightAxis->Title->Font->Size = 10;
Chart1->RightAxis->Title->Font->Style = TFontStyles() << fsBold; // QualiaIntensity用(第3系列) if (Chart1->SeriesCount() >= 3) {
Chart1->Series[2]->Title = “Qualia×0.01”;
Chart1->Series[2]->VertAxis = 1; // 右軸(または0で左軸)
}
//縦軸(右) タイトル
Chart1->RightAxis->Title->Caption = “Qualia÷200 / TopoW”;
Chart1->RightAxis->Visible = true;
//横軸 タイトル
Chart1->BottomAxis->Title->Caption = “Counter×0.1”;
Chart1->BottomAxis->Visible = true;
//スライダー初期値のラベル表示
Label3->Caption = AnsiString().sprintf(“Observation_strength(0.1~3.0) %.2f”, TrackBar_Observation_strength->Position * 0.01);
}
//—————————————————————————
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
if (graph) {
delete graph; // 上記のデストラクタが呼ばれる
graph = NULL;
}
}
//—————————————————————————
void __fastcall TForm1::Button5Click(TObject *Sender)
{
if (graph) graph->UpdateAll(0.1);
graph->DebugDump(Memo1, 0);
}
//—————————————————————————
//(手動CPTテスト)
void __fastcall TForm1::ButtonCPTClick(TObject *Sender)
{
if (!graph) return;
Memo1->Lines->Add(“=== 手動CPTテスト開始 ===”);
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (container) {
double before = container->topological_winding;
// CPT適用
container->ApplyCPT();
// SubStructureに適用
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
RecursiveLoop* lp = *it;
if (lp) lp->ApplyCPT();
}
}
// 更新
graph->UpdateAll(0.25);
AnsiString str;
Memo1->Lines->Add(str.sprintf(“CPT適用後 TopoW: %.4f (前: %.4f)”,
container->topological_winding, before));
}
Memo1->Lines->Add(“=== 手動CPTテスト終了 ===”);
}
//—————————————————————————
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
//Memo1,2の表示をしないことで、計算優先とし、タイマー周期を短くする
if(CheckBox1->Checked){
Memo1->Show();
Memo2->Show();
}else{
Memo1->Hide();
Memo2->Hide();
}
}
//—————————————————————————
void __fastcall TForm1::Button6Click(TObject *Sender)
{
AnsiString str;
//現在の+3.0でも効果が出始めたので、以下のように**祈りの「波及力」**をさらに強くしてみましょう。
/* if (!graph) return;
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (!container) return;
Memo1->Lines->Add(“=== 祈り入力(強力波及版) ===”);
// 祈り入力(持続ブースト版)
container->phase += 8.0;
container->topological_winding += 1.2;
container->negentropy += 800.0;
container->qualiaIntensity += 300.0;
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
if (*it) {
(*it)->phase += 4.0;
(*it)->topological_winding += 0.8;
(*it)->negentropy += 400.0;
(*it)->qualiaIntensity += 150.0;
}
}
}
// より長い更新
for (int i = 0; i < 12; i++) { graph->UpdateAll(1.2);
}
Memo1->Lines->Add(str.sprintf(“祈り後 Qualia: %.2f, TopoW: %.4f, Neg: %.2f”,
container->qualiaIntensity, container->topological_winding, container->negentropy));
*/
/* if (!graph) return;
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (!container) return;
Memo1->Lines->Add(“=== 祈り入力(持続強化版) ===”);
// 持続的な強シフト
container->phase += 7.0;
container->topological_winding += 1.2;
container->negentropy += 1200.0;
container->qualiaIntensity += 400.0;
// Sub全体に強影響
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
if (*it) {
(*it)->phase += 4.0;
(*it)->topological_winding += 0.9;
(*it)->negentropy += 600.0;
(*it)->qualiaIntensity += 250.0;
}
}
}
// Mainにも波及
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id >= 300) {
(*it)->phase += 2.0;
(*it)->topological_winding += 0.4;
}
}
// 大量更新
for (int i = 0; i < 15; i++) { graph->UpdateAll(1.5);
}
Memo1->Lines->Add(str.sprintf(“祈り後 Qualia: %.2f, TopoW: %.4f, Neg: %.2f”,
container->qualiaIntensity, container->topological_winding, container->negentropy));
*/
/* if (!graph) return;
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (!container) return;
Memo1->Lines->Add(“=== 祈り入力(持続強化版) ===”);
// 持続的な強シフト
container->phase += 7.0;
container->topological_winding += 1.2;
container->negentropy += 1200.0;
container->qualiaIntensity += 400.0;
// Sub全体に強影響
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
if (*it) {
(*it)->phase += 4.0;
(*it)->topological_winding += 0.9;
(*it)->negentropy += 600.0;
(*it)->qualiaIntensity += 250.0;
}
}
}
// Mainにも波及
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id >= 300) {
(*it)->phase += 2.0;
(*it)->topological_winding += 0.4;
}
}
// 大量更新
for (int i = 0; i < 15; i++) { graph->UpdateAll(1.5);
}
Memo1->Lines->Add(str.sprintf(“祈り後 Qualia: %.2f, TopoW: %.4f, Neg: %.2f”,
container->qualiaIntensity, container->topological_winding, container->negentropy));
*/
/* if (!graph) return;
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (!container) return;
Memo1->Lines->Add(“=== 祈り入力(持続強化版) ===”);
// 持続的な強シフト
container->phase += 7.0;
container->topological_winding += 1.2;
container->negentropy += 1200.0;
container->qualiaIntensity += 400.0;
// Sub全体に強影響
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
if (*it) {
(*it)->phase += 4.0;
(*it)->topological_winding += 0.9;
(*it)->negentropy += 600.0;
(*it)->qualiaIntensity += 250.0;
}
}
}
// Mainにも波及
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id >= 300) {
(*it)->phase += 2.0;
(*it)->topological_winding += 0.4;
}
}
// 大量更新
for (int i = 0; i < 15; i++) { graph->UpdateAll(1.5);
}
Memo1->Lines->Add(str.sprintf(“祈り後 Qualia: %.2f, TopoW: %.4f, Neg: %.2f”,
container->qualiaIntensity, container->topological_winding, container->negentropy));
*/
/* if (!graph) return;
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (!container) return;
Memo1->Lines->Add(“=== 祈り入力(持続強化版) ===”);
// 持続的な強シフト
container->phase += 7.0;
container->topological_winding += 1.2;
container->negentropy += 1200.0;
container->qualiaIntensity += 400.0;
// Sub全体に強影響
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
if (*it) {
(*it)->phase += 4.0;
(*it)->topological_winding += 0.9;
(*it)->negentropy += 600.0;
(*it)->qualiaIntensity += 250.0;
}
}
}
// Mainにも波及
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id >= 300) {
(*it)->phase += 2.0;
(*it)->topological_winding += 0.4;
}
}
// 大量更新
for (int i = 0; i < 15; i++) { graph->UpdateAll(1.5);
}
Memo1->Lines->Add(str.sprintf(“祈り後 Qualia: %.2f, TopoW: %.4f, Neg: %.2f”,
container->qualiaIntensity, container->topological_winding, container->negentropy));
*/
if (!graph) return;
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (!container) return;
Memo1->Lines->Add(“=== 祈り入力(持続強化版) ===”);
Memo2->Lines->Add(“=== 祈り入力(持続強化版) ===”);
// 提案A: 共鳴強化(現在の状態に比例させる)
//double resonance = 1.0 + (container->negentropy / 800.0) + (container->qualiaIntensity / 200.0); // 共鳴係数
//祈り強度の調整: 現在の祈りブーストが強めなので、以下のように**resonance(共鳴)**を入れて安定化:
double resonance = 1.0 + (container->qualiaIntensity / 300.0); // 共鳴係数
double prayerStrength = 1.0; // 将来的にスライダーで調整可能
// 持続的な強シフト
container->phase += 7.0;
container->topological_winding += 1.2;
//container->negentropy += 1200.0;
//祈り強度の調整: 現在の祈りブーストが強めなので、以下のように**resonance(共鳴)**を入れて安定化:
container->negentropy += 800.0 * resonance;
container->qualiaIntensity += 400.0;
// Sub全体に強影響
if (container->subStructure) {
for (std::vector<RecursiveLoop*>::iterator it = container->subStructure->loops.begin();
it != container->subStructure->loops.end(); ++it) {
if (*it) {
(*it)->phase += 4.0;
(*it)->topological_winding += 0.9;
(*it)->negentropy += 600.0;
(*it)->qualiaIntensity += 250.0;
}
}
}
// Mainにも波及
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id >= 300) {
(*it)->phase += 2.0;
(*it)->topological_winding += 0.4;
}
}
// 大量更新
for (int i = 0; i < 15; i++) { graph->UpdateAll(1.5);
}
Memo1->Lines->Add(str.sprintf(“祈り後 Qualia: %.2f, TopoW: %.4f, Neg: %.2f”,
container->qualiaIntensity, container->topological_winding, container->negentropy));
Memo2->Lines->Add(str.sprintf(“祈り後 Qualia: %.2f, TopoW: %.4f, Neg: %.2f”,
container->qualiaIntensity, container->topological_winding, container->negentropy));
// 今後の強化案(すぐに試せるもの)Observeの効果を祈りと連動
// 祈りボタン(Button6Click)の最後にcontainer->Observe(0.8); を追加してみてください。
// → 祈りで「意図を注入」→ Observeで「観測・固定」する流れが自然になります。
container->Observe(0.8);
}
//—————————————————————————
void __fastcall TForm1::ButtonObserveClick(TObject *Sender)
{
if (!graph) return;
// === container(ID:100)を毎回検索 ===
RecursiveLoop* container = NULL;
for (std::vector<RecursiveLoop*>::iterator it = graph->loops.begin();
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (!container) {
Memo1->Lines->Add(“*** ERROR: Container ID:100 が見つかりません ***”);
return;
}
// Observe実行
double beforeQualia = container->qualiaIntensity;
double beforeTopo = container->topological_winding;
double Observation_strength = TrackBar_Observation_strength->Position * 0.01;
Label3->Caption = AnsiString().sprintf(“Observation_strength(0.1~3.0) %.2f”, Observation_strength);
container->Observe(1.0); // 強さは1.0固定、またはスライダー変数で調整 // または0.7?1.2で調整
Memo1->Lines->Add(AnsiString().sprintf(“Observe実行 (strength=%.1f)”, Observation_strength));
Memo2->Lines->Add(AnsiString().sprintf(“Observe実行 (strength=%.1f)”, Observation_strength));
Memo1->Lines->Add(“=== Observe実行 (現実化) ===”);
Memo2->Lines->Add(“=== Observe実行 (現実化) ===”);
Memo1->Lines->Add(AnsiString().sprintf(“Qualia後: %.2f, Phase: %.4f”,
container->qualiaIntensity, container->phase));
Memo2->Lines->Add(AnsiString().sprintf(“Qualia後: %.2f, Phase: %.4f”,
container->qualiaIntensity, container->phase));
Memo1->Lines->Add(AnsiString().sprintf(
“=== Observe実行 === Before Qualia: %.2f → After: %.2f | TopoW: %.4f → %.4f”,
beforeQualia, container->qualiaIntensity, beforeTopo, container->topological_winding));
Memo2->Lines->Add(AnsiString().sprintf(
“=== Observe実行 === Before Qualia: %.2f → After: %.2f | TopoW: %.4f → %.4f”,
beforeQualia, container->qualiaIntensity, beforeTopo, container->topological_winding));
// 即時反映
graph->UpdateAll(0.5);
}
//—————————————————————————
void __fastcall TForm1::TrackBar_Observation_strengthChange(TObject *Sender)
{
Label3->Caption = AnsiString().sprintf(“Observation_strength(0.1~3.0) %.2f”, TrackBar_Observation_strength->Position * 0.01);
}
//—————————————————————————
void __fastcall TForm1::ButtonPrayObserveClick(TObject *Sender)
{
//「祈り+Observeワンボタン」**を作成(1クリックで祈り→短い待機→Observe)。
//Button6Click(Sender);
//ButtonObserveClick(Sender);
// === container(ID:100)を毎回検索 ===
RecursiveLoop* container = NULL;
for (std::vector
it != graph->loops.end(); ++it) {
if (*it && (*it)->id == 100) {
container = *it;
break;
}
}
if (!container) {
Memo1->Lines->Add(“*** ERROR: Container ID:100 が見つかりません ***”);
return;
}
// container検索
if (container) {
container->phase += 4.0; // 軽めの祈り
// resonance付き祈り効果(一部)
double resonance = 1.0 + (container->qualiaIntensity / 300.0);
container->negentropy += 400.0 * resonance;
container->Observe(1.8); // 祈り後にObserve(2.02近辺)
}
graph->UpdateAll(1.0);
}
//—————————————————————————